I have this action defined in my form.phtml (Environment is magento).
form action="getUrl('contacts/index/post')
Now I need to know which controller is getting called so I can get the values in the backend.
That is pretty straight forward.
The first word contacts is the front-name which in magento standards is the module name. The second word index is the controller file name and the last word post is the action of the controller.
Because thats a core controller, you can find the file under /app/code/core/Mage/Contacts/controllers/IndexController.php
Look at the postAction() function.
Related
I have the next nested route redirect_to [:financier, product, section]
This works if I have a controller with the name of the last variable but my question is how can I change the name of the last controller and call it in a similar way? for example, the model is called document and I want to change the controller name how catalog
You can always use the routing helpers:
redirect_to(other_thing_path(#financier, product, section))
Where those represent elements of the other path as necessary.
I have a PHP CodeIgniter Controller with name index and have a method that get details of id kode ($kode) using API get method.
Now when i need to show kode data for example for id AALI
I call this URL
http://www.example.com/?q=AALI
My target
How to make user data accessible by next URLs
http://www.example.com/AALI
I've try using function _remap on code Igniter, but it still wont work.
Have a look at Codeigniter URLs
As per your statement, your controller name is index and there would be an index function in your controller which renders the default view. it means you have changed default_controller to index in your Config.php
Now if you read the link above about Codeigniter URLs, there is a way to get data which passed in the URL after "/" You have to load url helper you can either autoload(recommended) it or load it in your constructor or Controller as per your convenience
Then you can just type
$param=$this->uri->segment(2); // in case your URL is http://www.example.com/AALI
The first segment is controller itself, The second is the function if your url is complete and the third is the parameter in CI URL structure but if you are not providing function name the first segment will always be your controller . So the second is your parameter. Just save it in a variable and do what you like.
I've read the URI parameters user guide and still have a question:
http://codeigniter.com/user_guide/general/routing.html
With the following:
{http://myapp/locations/1} I get a 404 error...
{http://myapp/locations} appropriately executes the index() function in the Main controller
{http://myapp/locations/main/locations/1} works, and the value is passed properly to index($var)
I do have other functions in Main.
How is it possible to get the first line to work in order to clean URL's?
Thanks in advance,
Alan
CodeIgniter reads an url as domain/controller_name/method-name/method_parameters and in your first url here http://myapp/locations/1 the first portion (myapp) is your domain name, second (locations) is your controller name and the third portion should be controller's method name and in this case you've passed 1 and obviously there's no such a method name, so it's showing error.
if you pass domain/controller_name like you did here in this url http://myapp/locations, then CodeIgniter reads the first portion as the domain_name and the second portion as controller_name and when there is no third portion in the url then CodeIgniter calls the index method/function by default, so your second url is working.
In your last url you have http://myapp/locations/main/locations/1 and it's been read as
myapp-domain name
locations-controller name
main-method/function name
and rest of all are passed as main controller's arguments. So remember that, the third part of an url is method/function name and if third part is not given then CodeIgniter calls the index method by default and in that case you have to declare a default index method/function in that controller, otherwise an error will be occured.
I was wondering if the following can be done in codeigniter.
Let's assume I have a file, called Post.php, used to manage posts in an admin interface.
It has several methods, such as index (lists all posts), add, update, delete...
Now, I access the add method, so that the url becomes
/posts/add
And I add some data. I click "save" to add the new post. It calls the same method with an if statement like "if "this->input->post('addnew')"" is passed, call the model, add it to the database
Here follows the problem:
If everything worked fine, it goes to the index with the list of all posts, and displays a confirmation
BUT
No the url would still be posts/add, since I called the function like $this->index() after verifying data was added. I cannot redirect it to "posts/" since in that case no confirmation message would be shown!
So my question is: can i call a method from anther one in the same class, and have the url set to that method (/posts/index instead of /posts/add)?
It's kinda confusing, but i hope i gave you enough info to spot the problem
Cheers!
Use the redirect() in conjunction with CodeIgniter's Flash Data, or opt for AJAX.
I am trying to code my first codeigniter project. I have a login controller which basically filters the data inputed and calls a model function that checks if the user is found in the database.
What I am trying to do is reuse this controller on the index page. So basically I want to be able to do user login on the index page or on the normal controller page (index.php/login/) without code duplication.
I'm sure there is an easy way to do this, but I'm not sure what the best solution is. Make it a library?
Thanks!
For this I would simply make the form in your view post to the login controller.
As a more generic way to share code and logic throughout your application, take a look at this article:
CodeIgniter Base Classes: Keeping it DRY
You basically give each of your controllers a "type". Being logged in could be a criteria of one of your base controllers, which saves you trying to directly access any of your controllers which is bad mojo.
You can try creating a form on the index page and submit it to index.php/login/. This way you won't need two entry points.
Just do the same as you have done for the login View, specify the same action attribute of the form to the index View, and it will be sent to the same login controller with no need to create the two login controllers. You might want to append a query string in the action attribute of the form to distinguish from which View the request has come.