Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Since you asked me to point out this,</p> <p>There are so many flaws in your architecture</p> <p><strong>First</strong>,</p> <p>When you do it like,</p> <p><code>class apiCall extends mainClass {</code></p> <p>you break the <strong>Single Responsibility Principle</strong> and <strong>Liskov Substitution principle</strong> at the same time</p> <p><strong>Second</strong>,</p> <p>A controller should <strong>never</strong> echo anything</p> <p>MVC itself looks like </p> <pre><code>$modelLayer = new ModelLayer(); $view = new View($modelLayer); $controller = new Controller($modelLayer); $controller-&gt;indexAction($request); echo $view-&gt;render(); </code></pre> <p>You actually implementing something that is close to <strong>Model-View-Presenter</strong>, not <strong>MVC</strong></p> <p><strong>Third</strong></p> <p>Since your class starts from <code>api..</code> then there's no need to include that name in methods.</p> <p><strong>Fourth</strong>,</p> <p>You don't have to tightly couple <code>json_encode()</code> with generation logic. That method should only return an array, then you'd <code>json_encode()</code> that array. Benefits? 1) Separation of Concerns 2) You can event convert that array to <code>YAML</code> or <code>XML</code>, not only <code>JSON</code></p> <p>And also, you should avoid inheritance in your case. Write singular class that deals with ApiCalls. So, it would look like as,</p> <pre><code>final class ApiCall { /** * I'd use a name that makes sense * * @param string $username * @return array on success, FALSE on failure */ public function fetchByUsername($username) { $return = $api_auth-&gt;request( 'GET', $api_auth-&gt;url( '/cms-plug' ), array('username' =&gt; $username) ); if ($response !== false){ return $response; } else { return false; } } } </code></pre> <p>And you would use it like,</p> <pre><code>if (isset($_GET['username'])){ $api = new ApiCall(); $result = $api-&gt;fetchByUsername($_GET['username']); if ($result !== false){ // Respond as JSON die(json_encode($result)); } else { die('Wrong username'); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload