0

私はグーグルを使用していたでしょうが、私は外出しています。皆さんが解決策を手伝ってくれるか、戻ってくるまでに何が間違っているのか教えてくれることを願っています.

ファクトリのインスタンスをコントローラーに渡し、ファクトリを使用してコントローラーの別のインスタンスを開始したいことに基づいて、取得したこの 1 ビットに関連する

 Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 24 bytes) in C:\xampp\htdocs\includes\object_factory_inc.php on line 19

I'm here is here は、呼び出し元のファクトリとコントローラーです

工場

/* The purpose of this class is to create the instance of a class when needed and how needed.
        For example we could have created the controller object inline but in recognition
        of the polymorphic behavior of controllers we have the decided to create it in our object-
        factory class(this class) which serves to hide the logic of creating the correct instance of
        a specified controller. 

        For example the 'build_index_controller' function uses the second parameter
        of the parameters passed to it to decide on the instance of the index to call
        */


class object_factory_inc
{
    public function build_controller($controller_name,array $controller_params)
    {
        $indexed_controller_params=array_values($controller_params);
        $controller_name=strtolower($controller_name);


        if(!isset($indexed_controller_params[0]))
        {

            $controller_name=$controller_name."_controller";
            return new $controller_name($this,$controller_params);

        }

        else
        {
            $controller_build_function="build_".$controller_name."_controller";
            method_exists($this,$controller_build_function)?$this->$controller_build_function($controller_name,$controller_params,$indexed_controller_params):$this->controller_doesn't_exist($controller_build_function);
                }

            }

            private function build_index_controller($controller_name,array $controller_params,array $indexed_controller_params)
            {
                strtolower($indexed_controller_params[0]);
                switch ($indexed_controller_params[0])
                {
                    case "s":
                    $controller_name=$controller_name."_search_controller";
                    return new $controller_name($this,$controller_params);
                    break;

                    case "admin":
                    $controller_name=$controller_name."_admin_controller";
                    return new $controller_name($this,$controller_params);
                    break;

                    case "loggedin":
                    $controller_name=$controller_name."_loggedin_controller";
                    return new $controller_name($this,$controller_params);
                    break;

                    default://if it doesn't exist just run default controller behaviour consider running 404
            $controller_name=$controller_name."_controller";
            return $controller_name($this,$controller_params);
        }

    }


    private function controller_doesnt_exist($controller_name)
    {
        echo "404 error ".$controller_name." doesn't exist on this server";
    }
}

実行しようとしているコントローラー:

     class index_controller
    {

    protected $parameters=array();
    protected $default_operation='view';
    protected $object_factory;

    public function __construct(object_factory_inc $factory,array $parameters )
     {
        $this->object_factory=$factory;
        $this->parameters=$parameters;
        $this->varify_controller();
        //print_r($parameters);
        //var_dump($factory);
        //require_once "views/index_view.php";


      }

      private function varify_controller()
      {
          if(true)//if logged in session is set;
          {
              $indexd_parameteres=array_values($this->parameters);
              $indexd_parameteres[0]='loggedin';
              $this->object_factory->build_controller("index",$this->parameters);
          }
      }

    }

the normal way the controllers are usually called are from the index here it is

    require_once 'includes/config.php';


        $route=isset($_GET['action'])?new router_controller($_GET['action']):new router_controller($_GET['action']="/index");
        $route->parse_route();
        $object_factory=new object_factory_inc;
        $controller=$object_factory->build_controller($route->get_controller(),$route->get_request_data());

長い質問で申し訳ありませんが、事前に必要なものをすべて提供したかったので、もし私が何か完全に間違ったことをしている場合は、私をグーグルに誘導するつもりなら、少なくともグーグルに何かを与えてください。

4

2 に答える 2

1

このラインはIndexControllerまさにその時を再現しています。

$this->object_factory->build_controller("index",$this->parameters);

index_controllerオブジェクト ファクトリ (上記の行) を介して作成すると、 new は、 this 内で定義されてIndex_Controllerいるように を呼び出します( が最初にインスタンス化されたときに自動的に実行されます)。varify_controller__construct()Index_Controller

varify_controller()への別の呼び出しが含まれてbuild_controller("index",$this->parameters);いるため、最初に戻り、メモリ制限を超えるまで新しいインデックス コントローラーを無限に作成します。

オブジェクトの構築にコンストラクターを使用することで、将来これらの問題を回避できます。これには、オブジェクトのプロパティの設定やオブジェクトの引数の解決など、オブジェクトを使用できるようにするために必要なタスクの実行のみを含める必要があります。

于 2013-10-11T19:34:32.303 に答える
0

ページの上部に行を追加してメモリを増やします

ini_set('memory_limit', '512M');

于 2013-10-11T19:29:33.817 に答える