I have been building the ImageUpload module. At first I created my module by the shell command. Then, I attached the ajax button in order to invoke a module action (it actually is a controller action in module).
<?php
class DefaultController extends CController
{
public function actionIndex()
{
$this->render('index');
}
}
modules/ImageUpload/views/default/index.php:
<p>
This is the view content for action "<?php echo $this->action->id; ?>".
The action belongs to the controller "<?php echo get_class($this); ?>" in the "<?php echo $this->module->id; ?>" module.
</p>
<p>
You may customize this page by editing <tt><?php echo __FILE__; ?></tt>
</p>
I have a module view file that is also generated by the shell, but I am not sure how to display it, since the display does not change at all when I click the button. Does anyone point the problem out?
Please check the generated HTML source about the ajax URL. You should use createUrl('index') or createUrl('default/index'), since the module ID will be automatically prefixed to it.
[error] [exception.CHttpException.404] exception 'CHttpException' with message 'Unable to resolve the request "default/index".' in /var/www/html/yii/framework/web/CWebApplication.php:336
[error] [exception.CHttpException.404] exception 'CHttpException' with message 'The system is unable to find the requested action "index".' in /var/www/html/yii/framework/web/CController.php:398
And it reached the line '$this->render('index');' as well, nothing is shown.
May be I am missing something in terms of ajax, e.g. header() or something, (though it is of no effect in this case), because the view has been rendered (finished).
I have read the article that says the ajax function sends some information from the client to the host asynchronously (It is OK so far). It says that the returned information from the host is received by ajax script(javascript)
As there is no page display by using the following code, I think I should receive some information from the controller by using javascript, and should not use the controller to alter view.
Is this the right idea on using ajax?
<?php
class DefaultController extends CController
{
public function actionIndex()
{
$this->render('index'); // surely here comes, but unfortunately, no page rendering here!
}
}
[error] [exception.CHttpException.404] exception 'CHttpException' with message 'Unable to resolve the request "imageupload".' in /var/www/html/yii/framework/web/CWebApplication.php:336
I inserted Yii::trace method and found that it surely executes renderPartial because this is ajax request. But unfortunately, there is no new display on the screen. I should investigate header or something like that…