i have problem in calling action from different controller using renderPartial.
I have one controller 'SiteController'. In which i call action from another controller 'AbcController'.
$this->renderPartial('Abc/_jobList',array('value'=>$value));
But i get following error
SiteController cannot find the requested view "Abc/_jobList".
Even i use
$this->renderPartial('//Abc/_jobList',array('value'=>$value));
and i get same error.
How can i solve it??
I think you are trying to access different controller's view.
For that you can access that by
$this->renderPartial('application.views.abc._jobList',array('value'=>$value));
But if you want to call another controller action then You have to redirect to that action from your current action using
$this->redirect("controllername/functionname")
Related
I'm making an Ajax call from a default Blade layout, shared by all the pages. The Ajax call is handled in AjaxController and the controller needs to know "what" is calling it.
Normally, I would do the following to check the current route:
$request->route()->getActionName(); // => e.g. "AjaxController#index"
But how do I retrieve the action name of a page from which the ajax call was made? So:
Ajax call is made from page A to controller X
Controller X checks what the route name of page A is
In the end, I can always pass the caller route name with the Ajax call, but I'm wondering if there's a way to know the caller from within the AjaxController.
I work in laravel but in that we define in routes.php which controller action is to call on perticular url for eg.
route::get("login", "loginController#getLogin");
here we defining to call getLogin Action of controller loginController.php when thi url is hit http://********.com/login
but Now I am working with yii and it seems messy because i had defined a Action in controller posting the data to the action from view but view gives error because it didn't know which controller function . it gives invalidRouteException I found it in error_log.
you can use UrlHelper
$url = Url::to(['post/view', 'id' => 100]);
In this case is called the controller post the action view with the id=100
see this doc for guide http://www.yiiframework.com/doc-2.0/guide-runtime-routing.html
http://www.yiiframework.com/doc-2.0/guide-helper-url.html
I have this two file path:
1: /api/math/application/controllers/test.php
2: /learn/mathtek/application/controllers/Auth.php
I need to call the controller from path2(Auth) inside the controller of path1(test). Is this possible? if yes how?
Ive tried to used the redirect() function but didnt work.
Also i tried this:
require_once('/learn/mathtek/application/controllers/Auth.php');
$aObj = new a(); //create object
$aObj->custom_a(); //call function
but it still didnt work...help please ... newbie in codeigniter here
Thanks guys for the help. I ended up doing a direct post of the path using redirect function to make it work.
1: /api/math/application/controllers/test.php - codeigniter1
2: /learn/mathtek/application/controllers/Auth.php - codeigniter2
Examples:
If i want to call path(2) from path(1).
redirect('http://localhost/learn/mathtek/auth/signin'); --'signin' is a function inside 'auth' controller
thats the code inside the 'test' controller. This works in codeigniter even if its from different path of controller.
However this doesnt work for UNITY(WEBGL). Thats why i ended doing an echo and returning it back.
You can't call any other controller action/method for have output or return value in your controller action/method because it is out of rules of MVC.
But you can redirect from one controller action to another controller action and pass argument in another controller action like below:
redirect("CONTROLLER/ACTION/ARGUMENT1/ARGUMENT2");
Edit:
suppose you are in Test controller and in test_method() action of Test controller then you can put your business logic code in the method and got some output and now you want to call any other controller function(eg: Auth) for perform any other operation with that output then you can pass that output in a redirect function as below:
redirect("Auth/auth_method/ARGUMENT1/ARGUMENT2");
I am confused with codeigniter routing. I am implementing URL masking in my project by using router in codeigniter.
From this I got confusion about the routing.routes has given below.
$route['project/shareToFacebook/(:any)']="project/shareToFacebook/$1";
$route['project/shareToFacebook/(:any)']="project/profile/$1";
My question is when I called the controller shareToFacebook what does route will do?
whether controller profile will be invoke or the controller shareToFacebook will be invoke?
Note: Routes will run in the order they are defined. Higher routes will always take precedence over lower ones.
CodeIgniter user guide: Routing
You will always be sent to shareToFacebook, but you will be sent to any of these routes only if you pass some parameters so when you will call the controller it will open it's index method regardless, if you won't pass any arguments.
when I called the controller shareToFacebook what does route will do?
The method 'shareToFacebook' will accept 1 parameter ex.
if you call ex. localhost/yourproject/profile/shareToFacebook/1 <- will be passed on the method shareToFacebook
public function shareToFacebbok($value)
and you can do what ever you want with that value.
whether controller profile will be invoke or the controller shareToFacebook will be invoke?
No.
profile will still call its index method
I am new to Codeigniter. While trying to access controller specific method, I am getting 'Object Not found' exception.
Before hitting the url I did following changes:
base_url set as http://localhost/test/ in config.php
default_controller set as main
Defined index and login method in main.php class
If I try to hit just http://localhost/test/, it returns echo from the index method. But if I directly give http://localhost/test/main/login then it throws Object not found exception. Strangely if I give $this->login(); into index method of main controller class, http://localhost/test/hits the login method. I have tried to change login method to public but no luck.
What I am missing here?
It seems to be the common index.php problem
This should do it: http://ellislab.com/codeigniter/user-guide/general/urls.html
But please confirm it by trying to access the controller with a index.php in behind it like so:
http://localhost/test/index.php/main/login