Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Zend framework Zend框架中的jQueryAjax_Zend Framework_Zend Form_Zend Db_Zend Form Element - Fatal编程技术网

Zend framework Zend框架中的jQueryAjax

Zend framework Zend框架中的jQueryAjax,zend-framework,zend-form,zend-db,zend-form-element,Zend Framework,Zend Form,Zend Db,Zend Form Element,我是ZF的新手,我想创建一个指向“任务”控制器和“ajax”操作的ajax链接 做这样的事 $registry = Zend_Registry::getInstance(); $DB = $registry['DB']; $sql = "SELECT * FROM task ORDER BY task_name ASC"; $result = $DB->fetchAll($sql); 然后将结果放在这个div中 <div id="container">container&

我是ZF的新手,我想创建一个指向“任务”控制器和“ajax”操作的ajax链接 做这样的事

$registry = Zend_Registry::getInstance();  
$DB = $registry['DB'];
$sql = "SELECT * FROM task ORDER BY task_name ASC";
$result = $DB->fetchAll($sql);
然后将结果放在这个div中

<div id="container">container</div>
容器
这是我的观点,我正在做这件事

<?php echo $this->jQuery()->enable(); ?>
<?php echo $this->jQuery()->uiEnable(); ?>
<div id="container">container</div>
<?php  
echo $this->ajaxLink("Bring All Task","task/ajax",array('update' => '#container'));
?>

容器
我不知道语法我将如何做到这一点,润色我的代码如果我错了我搜索了很多,但都是徒劳的请解释我感谢大家在期待中也参考我一些不错的链接zendx_jquery教程

这应该可以工作:

class IndexController extends Zend_Controller_Action 
{
    /**
     * Homepage - display result of ajaxRequest
     */
    public function indexAction()
    {
    }

    /**
     * Print result of database query 
     */
    public function ajaxAction()
    {   
        // disable rendering of view and layout
        $this->_helper->layout()->disableLayout();


        $registry = Zend_Registry::getInstance();  
        $db =  $registry['DB'];

        // get select object to build query 
        $select = $db->select();
        $select->from('task')->order('task_name ASC');

        // echo result or what ever..   
        $this->view->tasks = $db->fetchAll($select);
    }
}    



// index.phtml (view)
<?php 

    echo $this->jQuery()->enable(); 
    echo $this->jQuery()->uiEnable();

    // create link to ajaxAction
    $url = $this->url(array(
        'controller' => 'index',
        'action'     => 'ajax',
    ));
?>

<div id="container">container</div>

<?php 
    echo $this->ajaxLink(
        "Bring All Task", $url, array('update' => '#container')
    ); 
?>

这将打印一个数组??如果我想把它放在HTML中,我将在视图中在哪里编写HTML代码???。请不要介意我的尴尬问题,我是新来的,这取决于你的专栏。简单的方法:从控制器操作打印html。是否$db可以在php中访问,这是通过AJAX调用的。我正在尝试,但不工作。您的注册表可能有问题?很难帮助你对不起
<?php  if ($this->tasks): ?>
  <table>
    <tr>
         <th>task ID</th>
         <th>task Name</th>
    </tr>
  <?php foreach($this->tasks as $task) : ?>
    <tr>
       <td><?php echo $task['task_id']; /* depending on your column names */ ?>
       </td>
       <td><?php echo $this->escape($task['task_name']); /* to replace " with &quot; and so on */ ?>
       </td>
    </tr>
  <?php endforeach; ?>
  </table>
<?php else: ?>
  No tasks in table.
<?php endif; ?>
$db = Zend_Db::factory('Pdo_Mysql', array(
  'host'     => '127.0.0.1',
  'username' => 'webuser',
  'password' => 'xxxxxxxx',
  'dbname'   => 'test'
));
Zend_Registry::set('DB', $db);