getting the string to read as php zend statement

Discussion in 'PHP' started by jigen7, Jun 9, 2009.

  1. #1
    Hi I' using zend as my framework, which i've got a problem, what i want to do is ill get the crit base on the get_param then the id is the modelname which i'll append to this command " new Model_Select_.'$table'.(); " as all of my models have the same ane format ony changing their tablename

    . but it'll give me the error "Parse error: syntax error, unexpected ')" can anyone help me through this?
    
        $table = $this->_getParam('crit');
        $curr_model = new Model_Select_.'$table'.(); //it will not accept this 
        $this->view->table = $curr_model->fetchAll();  
    
    PHP:
    i tried storing the statement as
    $string = " new Model_Select_.'$table'.();";
    $curr_model = $string;
    
    PHP:
    but the result is the statement was read as a string instead of processing the action, i tried the eval() code but its not working
    
    $curr_model = eval("new Model_Select_".$table."();");
    
    Code (markup):
    thanks
     
    jigen7, Jun 9, 2009 IP
  2. Vooler

    Vooler Well-Known Member

    Messages:
    1,146
    Likes Received:
    64
    Best Answers:
    4
    Trophy Points:
    150
    #2
    $table = $this->_getParam('crit');    
    
    [B]$string = " \$curr_model = new Model_Select_{$table}();";[/B]
    eval($string);
    
    $this->view->table = $curr_model->fetchAll();
    Code (markup):
     
    Vooler, Jun 9, 2009 IP