Trying to call imagemagick using this code. The errors are with the appcontroller, myadoptscontroller, and index. I have been talking to someone who also uses the Mysidia Adoptables code and they provided me their code to edit, I edited their code but it is throwing these errors and I’m not well versed in coding enough to fix them. I have tried myself and using ai tools but the issues still remain. I have been trying to get the site running for weeks now so any help would be greatly appreciated. The full paragraph of errors is too confusing for me to fix, but I tried to fix the two above it. I’m wondering if ther $adopt variable is due to me removing the $species in the original code but I’m not sure. I tried looking up the attempt to read property aid on null but couldn’t find anything useful on how to fix it in regards to my problem.

The error:

Warning: Undefined variable $adopt in /home/pixellat/public_html/model/domainmodel/ownedadoptable.php on line 132

Warning: Attempt to read property "aid" on null in /home/pixellat/public_html/model/domainmodel/ownedadoptable.php on line 132

Fatal error: Uncaught TypeError: ResourceCoreAppController::setField(): Argument #2 ($value) must be of type ?ResourceNativeObjective, string given, called in /home/pixellat/public_html/controller/main/myadoptscontroller.php on line 47 and defined in /home/pixellat/public_html/resource/core/appcontroller.php:183 Stack trace: #0 /home/pixellat/public_html/controller/main/myadoptscontroller.php(47): ResourceCoreAppController->setField('image', '/adoptimage/vie...') #1 [internal function]: ControllerMainMyadoptsController->manage('1') #2 /home/pixellat/public_html/resource/core/frontcontroller.php(196): ReflectionMethod->invokeArgs(Object(ControllerMainMyadoptsController), Array) #3 /home/pixellat/public_html/controller/main/indexcontroller.php(13): ResourceCoreFrontController->triggerAction() #4 /home/pixellat/public_html/resource/core/frontcontroller.php(142): ControllerMainIndexController->triggerAction() #5 /home/pixellat/public_html/index.php(75): ResourceCoreFrontController->handleRequest() #6 /home/pixellat/public_html/index.php(84): IndexController->run() #7 /home/pixellat/public_html/index.php(88): IndexController::main() #8 {main} thrown in /home/pixellat/public_html/resource/core/appcontroller.php on line 183

Appcontroller:

<?php

namespace Resource\Core;
use ReflectionException, ReflectionMethod;
use Resource\Collection\HashMap;
use Resource\Exception\AlreadyLoggedinException;
use Resource\Exception\GuestNoaccessException;
use Resource\Exception\InvalidActionException;
use Resource\Native\MysString;
use Resource\Native\Objective;

/**
 * The Abstract AppController Class, extends from abstract controller class.
 * It is parent to all application controller type classes, they are vast in numbers.
 * @category Controller
 * @package Controller
 * @author Hall of Famer
 * @copyright Mysidia Adoptables Script
 * @link http://www.mysidiaadoptables.com
 * @since 1.3.2
 * @todo Not much at this point.
 * @abstract
 *
 */

abstract class AppController extends Controller{

     /**
     * The access property, specifies the access control of this controller.
     * @access protected
     * @var String
     */
    protected $access;

    /**
     * The fields property, stores a map of key-value pairs to be passed to View.
     * @access protected
     * @var HashMap
     */
    protected $fields;

    /**
     * The frontController property, holds a reference to the front-controller that delegates to this app-controller.
     * @access protected
     * @var frontController
     */
    protected $frontController;         

    /**
     * The subController property, holds a reference to the sub-controller available for this app-controller.
     * @access protected
     * @var SubController
     */
    protected $subController;     

    /**
     * Constructor of AppController Class, which initializes basic controller properties.
     * @param String  $access
     * @access public
     * @return void
     */
    public function __construct($access = ""){
        $mysidia = Registry::get("mysidia");
        $this->access = $access;
        $this->frontController = $mysidia->input->get("frontcontroller");
        $this->action = $mysidia->input->action();
        $this->name = $mysidia->input->get("appcontroller");
        $this->fields = new HashMap;

        if(!$this->hasAction($this->action)){
            throw new InvalidActionException("global_action");
        }
        if(!empty($this->access)) $this->handleAccess();       
    }

    /**
     * The getAccess method, getter method for property $access.
     * @access public
     * @return String
     */   
    public function getAccess(){
        return $this->access;
    }   

    /**
     * The getFields method, getter method for property $fields.
     * @access public
     * @return HashMap
     */   
    public function getFields(){
        return $this->fields;
    }

    /**
     * The getFrontController method, getter method for property $frontController.
     * @access public
     * @return FrontController
     */   
    public function getFrontController(){
        return $this->frontController;
    }   

    /**
     * The getSubController method, getter method for property $subController.
     * @access public
     * @return SubController
     */   
    public function getSubController(){
        return $this->subController;
    }   

    /**
     * The getView method, getter method for property $view.
     * @access public
     * @return View
     */   
    public function getView(){
        if(!$this->view){
            if($this->subController instanceof SubController) $this->view = $this->subController->getView();
            else $this->loadView($this->name);
        }   
        return $this->view;
    }

    /**
     * The loadView method, it loads the corresponding view for the controller.
     * @param String  $name
     * @access public
     * @return View
     */   
    public function loadView(MysString $name){
        $viewClass = "View\\{$this->frontController}\\{$name->capitalize()}View";
        $this->view = new $viewClass($this);
    }

    /**
     * The handleAccess method, carries out basic access control
     * At this point it only distinguishes member-only and guest-only pages, but in future it will handle more.
     * This method is protected since AppController::handleAccess() can be invoked by child classes at any time.
     * @access protected
     * @return void
     */   
    protected function handleAccess(){
        $mysidia = Registry::get("mysidia");
        if($this->access == "member" && !$mysidia->user->isLoggedIn()){
            throw new GuestNoaccessException($mysidia->lang->global_guest);
        }
        if($this->access == "guest" && $mysidia->user->isLoggedIn()){
            throw new AlreadyLoggedinException($mysidia->lang->global_login);
        }
    }

    /**
     * The hasAction method, checks if an action exists in this controller.
     * @access private
     * @return Boolean
     */   
    private function hasAction(){
        try{
            $method = new ReflectionMethod($this, $this->action);
            return $method->isPublic();
        }
        catch(ReflectionException $rle){
            return FALSE;
        }
    }   

    /**
     * The index method, construct a default index page.
     * The actual view construction is delegated to view class, this method exists for the sole purpose for reflection method to work.
     * @access public
     * @return void
     */       
    public function index(){}

    /**
     * The setField method, inserts a specific key-value pair into the field map.
     * @param String  $key
     * @param Objective  $value
     * @access public
     * @return void
     */   
    public function setField($key, Objective $value = NULL){
        $this->fields->put(new MysString($key), $value);
    }

    /**
     * The setFields method, setter method for property $fields.
     * @param HashMap  $fields
     * @access public
     * @return void
     */   
    public function setFields(HashMap $fields){
        $this->fields = $fields;
    }

    /**
     * The setFlags method, setter method for property flags.
     * @param String  $param
     * @param String  $param2
     * @access protected
     * @return void
     */       
    public function setFlags($param, $param2 = NULL){
        $this->frontController->setFlags($param, $param2);
    }

    /**
     * The setFrontController method, setter method for property $frontController.
     * @param FrontController  $frontController
     * @access public
     * @return FrontController
     */   
    public function setFrontController(FrontController $frontController){
        $this->frontController = $frontController;
    }   

    /**
     * The setSubController method, setter method for property $subController.
     * @param SubController  $subController
     * @access public
     * @return void
     */   
    public function setSubController(SubController $subController){
        $this->subController = $subController;
    }       
}

Myadoptscontroller:

<?php

namespace Controller\Main;
use Model\DomainModel\AdoptNotfoundException;
use Model\DomainModel\OwnedAdoptable;
use Model\DomainModel\PoundAdoptable;
use Model\DomainModel\Vote;
use Model\Settings\PoundSettings;
use Model\ViewModel\OwnedAdoptableViewModel;
use Resource\Collection\ArrayList;
use Resource\Core\AppController;
use Resource\Core\Model;
use Resource\Core\Pagination;
use Resource\Core\Registry;
use Resource\Exception\NoPermissionException;
use Resource\Native\MysString;

class MyadoptsController extends AppController{

    private $adopt;

    public function __construct(){
        parent::__construct("member");
        $mysidia = Registry::get("mysidia");
        if($mysidia->systems->adopts != "enabled") throw new NoPermissionException("The admin has turned off adoption feature for this site, please contact him/her for detailed information.");
    }

    public function index(){
        $mysidia = Registry::get("mysidia");
        $total = $mysidia->user->countOwnedAdopts();
        if($total == 0) throw new AdoptNotfoundException($mysidia->lang->empty);
        $pagination = new Pagination($total, $mysidia->settings->pagination,
                                     "myadopts", $mysidia->input->get("page"));
        $stmt = $mysidia->db->join("adoptables", "adoptables.id = owned_adoptables.adopt")
                           ->select("owned_adoptables", [], "owner ='{$mysidia->user->getID()}' ORDER BY totalclicks LIMIT {$pagination->getLimit()},{$pagination->getRowsperPage()}");
        $ownedAdopts = new ArrayList;
        while($dto = $stmt->fetchObject()){
            $ownedAdopts->add(new OwnedAdoptableViewModel(new OwnedAdoptable($dto->aid, $dto)));
        }
        $this->setField("pagination", $pagination);
        $this->setField("ownedAdopts", $ownedAdopts);
    }

    public function manage($aid){
        $this->initOwnedAdopt($aid);
        $this->setField("ownedAdopt", $this->adopt);   
        $this->setField("image", $this->adopt->getImage(Model::GUI));       
    }

    public function stats($aid){
        $mysidia = Registry::get("mysidia");
        $this->initOwnedAdopt($aid);
        $stmt = $mysidia->db->select("vote_voters", [], "adoptableid='{$this->adopt->getAdoptID()}' ORDER BY date DESC LIMIT 10");
        $votes = new ArrayList;
        while($dto = $stmt->fetchObject()){
            $votes->add(new Vote(NULL, NULL, NULL, NULL, $dto));
        }
        $this->setField("ownedAdopt", new OwnedAdoptableViewModel($this->adopt));   
        $this->setField("votes", $votes);
    }

    public function bbcode($aid){
        $this->initOwnedAdopt($aid);
        $this->setField("adopt", $this->adopt);   
    }

    public function rename($aid){
        $mysidia = Registry::get("mysidia");
        $this->initOwnedAdopt($aid);
        if($mysidia->input->post("submit")){
            if(!$mysidia->input->post("adoptname")){
                $this->setFlags("rename_error", "rename_empty");
                return;   
            }

            $poundsettings = new PoundSettings($mysidia->db);
            $isPounded = $mysidia->db->select("pounds", ["aid"], "aid='{$this->adopt->getAdoptID()}'")->fetchColumn();
            if($isPounded && $poundsettings->rename == "yes"){
                $poundAdopt = new PoundAdoptable($aid);
                if($poundAdopt->getFirstOwner() != $mysidia->user->getID()){
                    $this->setFlags("rename_error", "rename_owner");
                    return;   
                }               
            }           
            $this->adopt->setName($mysidia->input->post("adoptname"), Model::UPDATE);
        }
        $this->setField("adopt", $this->adopt);       
        $this->setField("image", $this->adopt->getImage(Model::GUI));           
    }

    public function trade($aid, $confirm = NULL){
        $this->initOwnedAdopt($aid);
        if($confirm){
            $tradeStatus = ($this->adopt->getTradeStatus() == "fortrade") ? "notfortrade" : "fortrade";
            $this->adopt->setTradeStatus($tradeStatus, Model::UPDATE);
        }
        $this->setField("adopt", $this->adopt);
        $this->setField("image", $this->adopt->getImage(Model::GUI));   
        $this->setField("confirm", $confirm ? new MysString($confirm) : NULL);               
    }

    public function freeze($aid, $confirm = NULL){
        $this->initOwnedAdopt($aid);
        if($confirm){
            $frozen = ($this->adopt->isFrozen() == "yes") ? "no" : "yes";
            $this->adopt->setFrozen($frozen, Model::UPDATE);               
        }     
        $this->setField("adopt", $this->adopt);
        $this->setField("image", $this->adopt->getImage(Model::GUI));   
        $this->setField("confirm", $confirm ? new MysString($confirm) : NULL);
    }

    private function initOwnedAdopt($aid){
        $mysidia = Registry::get("mysidia");
        $this->adopt = new OwnedAdoptable($aid);   
        if(!$this->adopt->isOwner($mysidia->user)) throw new NoPermissionException("permission");               
    }
}

Recommended Answers

All 3 Replies

While I've used ImageMagick over a decade ago, I didn't use it from PHP.
So I suggest you work this with a MVE (minimal viable example.)

That is, start with working code and change ONE LINE. No more.
Then share that line and the new line so I can see if I can find Waldo.

I can look into this tomorrow if you still need help. Sorry, I’ve been feeling sickly yesterday and today.

PHP is pretty good and expressive with warning , error and exception messages. If you don't understand anything from the messages that you get please write more about what exactly you don't understand and we could make it clearer. But ... ignoring warnings is a bad practice because there is a probability to lead in fatal errors , so first fix the warnings and then move to the fatal error.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.