I was under the impression (after viewing some tutorials on Alan Storms site about Models) that I should be able to call a function on my controller via a url like so:
http://www.localhost.com:8080/magento/index.php/mymodule/adminhtml_mymodule/someFunction
and in the controller declare:
public function someFunctionAction()
{
Mage::log("Im In");
}
The problem is that nothing is being logged. Is there something special with admin modules that prevents this from working?
Note: I haven't included the rest of my code for declaring the module as everything is working fine, I am merely curious about calling the controller function via the Url in this way but please let me know if you require more information in order to answer it properly.
You can't call your action with the direct URL, because Magento uses nonces in the admin section. You can read about this here: http://alanstorm.com/magento_admin_hello_world_revisited , look for the "Magento Admin URLs"-section.
Try this, if your controller name is poductController than in URL use product
http://www.localhost.com:8080/magento/index.php/mymodule/product/someFunction
Related
I Need to call a function that is inside a joomla component, but to do this, I need to be logged in admin, I need to call this function inside a php script, that runs in the terminal.
What i have tried:
Use cURL to login and then call the function
Instantiate the component controller and call the function
Neither options works, on the first I cant figure out how to log in (I tried a script from other question not worked) and then use the 'session' to call the function.
On the second, i can instantiate a 'regular' component, but for a admin component i cant instatiate.
I tried to login using this question, and many similar others:
Joomla 2.5 login with curl
Thanks for the help
I'm building a simple CMS using Code Igniter version 3.0.0
The site's URLs are all customizable by the user and so do not follow the standard MVC structure of /controller/method/parameter-1/parameter-2/. Instead, all frontend traffic gets directed to PublicController's index method. This method searches the database for the current URL to return the correct page, and also the page type. Each page type corresponds to a controller.
How do I call that controller from the PublicController without doing a redirect?
I can't use the redirect() method because that would change the URL in the browser window and cause an un-need additional page request.
if you look at the url /about/who-we-are/
about is the controller and who-we-are is a function in the controller that loads one or more views.
The same for /locations/stores/
the functions stores in the controller locations.
read the documentation and it will be easy to understand.
http://www.codeigniter.com/user_guide/overview/mvc.html
I am pretty sure that configuring a route is your answer:
// routes.php
$route['(:any)'] = "PublicController/index/$1";
// PublicController.php
public function index()
{
var_dump(func_get_args());
}
I am using SS 3.02 and have made a lots of modification in the core files. I am facing the issue that I am trying to set the color of the navigation background dynamically. This works fine for pages other than security/login page. Suppose I am getting the value in $navbgcolor, this shows up well on home page or about us page or any other page. But this does not show up on the Security/login page. Any help would be greatly appreciated. Thanks.
Firstly, it is never a good idea to alter the core files as this prevents you from easily updating your version of SilverStripe. You could miss out on bug fixes and important security updates.
The reason this isn't working on the login page is because the login page works from the Security controller which directly extends Controller. Your code (presumably in Page_Controller) will be completely bypassed.
Here is a way you could apply your code to all controllers, without touching the core:
<?php
class MyControllerExtension extends Extension {
public function onAfterInit() {
//... Your code here...
}
}
In your config file you would apply your new controller extension to Controller.
If you're using _config.php
Object::add_extension("MyControllerExtension", "MyControllerExtension")
If you're using YAML (recommended)
Controller:
extensions:
- 'MyControllerExtension'
You can learn more about extensions here: http://doc.silverstripe.org/framework/en/reference/dataextension
Also to let you know, you can create specific template file for the Security login pages by creating action sub-templates. Example is if you created a file in your theme called "Security_login.ss" you can call in variable, change the mark up etc.
Note the convention here is the filename is called the name of the class in this case "Security" then "_" followed by the name of the action to be rendered by your controller ("login" in this case).
As mentioned by micmania1, the golden rule for developing in SilverStripe is...
"Don't hack the core or modules!"
Instead as pointed out use extensions to decorate classes, or use subclasses if you have to.
I want to implement a Phill Sturgeon CodeIgniter RESTServer library in my project. I copied the files rest.php, Format.php, REST_Controler.php in folders config,library,library respectively.
I created my controller called services with following code:
<?php
require(APPPATH.'/libraries/REST_Controller.php');
class services extends REST_Controller {
function Teams_get(){
$teamNames=$this->team_model->getTeamNames();
$this->response($teamNames);
}
TeamModel is autoloaded in my autoload.php. When I want to run Teams_get method in my browser result is:
{"status":false,"error":"Unknown method."}
I read here that I should change REST_Controler.php configuration file, but this change should only be done if POST methods are not working.
My services should be public, so I don't need authentication methods.
What's wrong here?
When calling your API, the URL should just be the name of the method, without the _get (or _post). That is added by the REST server depending on how the URL is called (GET vs POST).
So, to call your Teams_get method, you want to send a GET request to the URL /services/Teams (not /services/Teams_get).
Docs: https://github.com/philsturgeon/codeigniter-restserver#handling-requests
I think this is a route issue but I'm not sure. I have a page with this URL:
siteurl.com/kowmanger/titles/titles/edit/$id
I'm trying to find out that when I'm on this page I load the titles page it says page not found so I need to tell it that the $id is just a paramter so I can use it to get the data of the title.
UPDATE :
So I decided to change my titles controller so that there's a edit and add function inside of the titles controller that way they dont' have separate controllers when they are in fact methods.
So now I have:
kansasoutalwwrestling.com/kowmanager/titles/titles - list of titles
kansasoutalwwrestling.com/kowmanager/titles/titles/add - addnew form
kansasoutalwwrestling.com/kowmanager/titles/titles/edit/$id - edit form
I don't have any routes set up so far for this. For some reason though I"m getting the same page for both of these page.
kansasoutalwwrestling.com/kowmanager/titles/titles/add - addnew form
(right link url) kansasoutalwwrestling.com/kowmanager/titles/add -
addnew form
I need a route so that it'll show the correct url if the add method is accessed.
Also I need to set up a route so that if the correct edit link is accessed it sees the id attached to the end of the url and it'll accept it so that I can do a my database query to get the title data.
UPDATE: So to reiterate I have a module(subfolder) called titles. Inside of the module I have a controller called titles and inside of that controller I have 3 functions called index(), add(), edit().
I tried using Chris's suggestion on the routes but its not routing correctly. Also wanted to mention I'm using wiredesignz modular separation framework if that matters.
Any additional ideas?
Possible answer based on your post, not one hundred percent your entire structure but if i had to guess based off the post I would try this as my routes first..
$route['titles/titles/edit/(:any)'] = 'titles/titles/edit/$1';
$route['titles/titles/add'] = 'titles/titles/add';
$route['titles/titles'] = 'titles/titles';
$route['titles'] = 'titles/index';
Are you using custom routing in your configuration files ?
The general routing protocol used by codeigniter is like this:
domain.com/controller/methode/param1/param2/param3
This being said, your url
siteurl.com/kowmanger/titles/titles/edit/$id
corresponds to something like this :
class Kownmanger extends CI_Controller
{
public function titles($titles, $action, $id)
{
}
}
In case you are using sub-folders in your controllers folder, what I have just said will change, Could you please tell us what's your directory structure ?