I want a piece of code on the index of my Code Igniter's script so I can change the identety or name of my controller from agent69 to agent007_and_supergirl,and also a way to beat any rule that pages might have against using underscore to separate words as an amendment.
In other words I want that all the calls that the processor of my server has inside my code igniter for agent69 be translated to calls to agent007_and_supergirl
Is just a change of identety for the controller without altering the main controler's functionality and without getting my hands dirty with coding.
If you want re route your default controller url, you have to edit routing configuration like this:
in application/config/route.php
$route['agent007_and_supergirl'] = 'agent69';
Now agent69 Controller will be accessible by http://youriste.com/agent69 and http://yoursite.com/agent007_and_supergirl as well
CodeIgniter URI Routing Guide
Working on config/routes.php yelded miserabe results on past,remember that is an identity matter
And I want all the calls of agent69 be sent to agent007_and_supergirl that is its new identity
What was successfull on the past about this mattar was controller and file cloning,it worked masterfully
but this only intercepted few server calls so for me to get all the server calls, I need to clone every
single fie on the script so I feel silly teling you again thats why I didnt want to get my hands dirty with code
because is plenty of code.
Well hope that you can help me master this code that goes on the index of my code igniter script--///The code cant appear here so its below in the comment to lighta thanks 4 readin
Related
I have a PHP routing script, like this:
include_once('routing-functions.php');
// pathMatches was imported from routing-functions.php
if(pathMatches('/blog/*')){
include_once('actual-script.php');
}
The problem I have is the following: the functions and global variables from routing-functions.php could potentially conflict with the included file. Additionally, I don't want actual-script.php to have access to any of the variables of the router.
I am looking for a way to completely wipe the PHP context, so that the file is included as if it were directly requested, so doing the following is not an option because it changes the context/scope in which actual-script.php is executed:
if(pathMatches('/blog/*')){
function $sandbox(){
include_once('actual-script.php');
};
$sandbox();
}
Additionally, sending a local request to the file (e.g. with cURL) is also not an option, because it has a negative impact on performance and I want it to run as if it were under the /blog/ URL.
The problem is easy to solve with .htaccess, however, I need a dynamic solution that uses a PHP router.
If anyone has had a similar problem before or knows of a good solution it would be greatly appreciated.
I have been researching for almost 2 weeks on for an answer and have finally decided I needed to ask for help. I am quite unfamiliar with PHP/Drupal but has inherited such a project to update and maintain. The project runs on Drupal 8.3.7 and is hosted with IIS 6.2.
For some unknown reason, links in my html.twig files are being returned with a "null" base_url. So for example...
...
will link to "null/home" ... After a lot of hacking and trying to figure out if I could manually set $base_url (not a best practice, I know, but I just needed to see if it was possible), I found two peculiar behaviors:
A. If in the associated controller I create a variable $temp_base_url and hardcode the value "localhost" and attempt to put the following in my html.twig file (where item.url = "/home")...
http://{{temp_base_url}}{{item.url}}
The text between the anchor tag will show up correctly as http://localhost/home while the actual link will direct you to null/home .
B. On the other hand, if I assigned $temp_base_url to equal "http://localhost" and put the following code...
{{temp_base_url}}{{item.url}}
The text between the anchor tag will (aga) show up correctly as http://localhost/home while the actual link will now try to direct you to http://localhost/null/home .
The problem isn't with the global variable $base_url because when I test for this within the Controller, $base_url is setting itself correctly to "localhost" so I suspect Symfony or something else rendering the routes incorrectly (any attempts to use 'path' or 'url' has also resulted in similar null issues).
So my question is: Where are these nulls coming from? How do I get IIS/Drupal to pick up the appropriate base url for routing?
You can use this url('<front>')
{{ url('<front>') }}{{item.url}}
This is a 2 part question:
a. Is it possible to have a .php file as a view in Rails? Need it because at some point some data needs to be signed with a bank provided function -only in PHP-
<?php
$base64 = ".SignData("some data from rails", "private.key.pem")
?>
I tried in Rails something like:
..
render file "/home/myApp/app/view/signData.php.erb"
..
Also tried
..
render file "/home/myApp/app/view/signData.php"
..
But tells me "Template is missing". I know it is not a matter of path because if change .php to .html in path, it finds the file.
b. The other question: how to get back to rails the $base64 info obtained in PHP?
Thanks
Have you thought about having your web server reroute that one specific call to PHP instead of Rails? It might be the cleanest solution. Something like http://weblog.terrellrussell.com/2008/01/running-php-within-rails/.
You could make a separate, small PHP webservice to wrap this SignData method. You can host it on the same platform, which is handy, then call it from your main application with some straight forward Net::HTTP.
Edit: I thought about a possible solution, but I made another question as it is very specific: see AJAX proxy with PHP, is it possible?
A couple of times I've encountered this problem...
I create sites that have a certain degree of modularity. So, it is possible that there are "components" (think of a rough CMS) which carry their own PHP code, CSS, and JavaScript, all dynamically included. Think about a structure like:
{siteroot}/component/datagrid/datagrid.php
{siteroot}/component/datagrid/js/datagrid.js
{siteroot}/component/datagrid/css/datagrid.css
{siteroot}/component/datagrid/ajax/getsomedata.php
Now, the question is: for JavaScript files, and expecially AJAX calls, how do I make them context-aware with the URLs?
For example, if in datagrid.js I want to call siteroot/component/datagrid/ajax/getsomedata.php with AJAX I should write (with JQuery):
$("#ajax").load("siteroot/component/datagrid/ajax/getsomedata.php");
First problem: siteroot changes on different installations. I've managed that by including a general
var codeBase = <? echo json_encode(Config::$siteRoot); ?>
with PHP on every page, from a Config file that can be easily edited for every installation, so I can do with whatever JavaScript something like:
$("#ajax").load(codeBase + "/component/Datagrid/ajax/getsomedata.php");
What do you think of this approach?
Second problem: but I have PHP functions that return to me also the components folder, or the folder of other components. It would be nice to make the whole URL dynamic. This would account also for changes in the structure of the component if I want.
The only solution I've found is to use a .js.php dynamic Javascript. This is very unelegant, and I have to include all the framework in the JavaScript file, like:
<?php
include "../../libs/framework.php"; // get my functions...
$myUrl = Config::$siteRoot . Framework::getComponentAjaxDir("datagrid") . "/getsomedata.php";
?>
$("#ajax").load(<?=json_encode($myUrl)?>);
Another side effect is that I have to know exactly the include the path for framework.php... I don't want this so hard-codedin my ".js.php" file.
Any smart solutions about that?
As nobody answered in a suitable way, I answer to myself to provide a solution I've found out that can be useful.
The key to my solution is simple:
I create an AJAX proxy at a fixed location in my site structure, so I can use codeBase to reference the proxy from JavaScript
I call this proxy with two parameters: plugin and action, which identify a) the plugin folder in which the "real" ajax is and b) the ajax file to use, along with the other params:
$("#...").load( codeBase + "/main/ajax.php?plugin=Datagrid&action=gettable&otherparams"...)
In ajax.php I sanitize the parameters, and use plugin and action to obtain the "real" ajax file:
{serverRoot}/components/{plugin}/ajax/{action}.php
Then i simply include that file in ajax.php
To be honest your problems are realistic options and aren't that bad practice in general quite frankly.
But let's explore this a little further.
What would be the best approach is for you to have 1 main config.php file which you can then specify modules, i.e. your datagrid etc.
You could store all modules in an array variable like so:
$_SITE_PATH = "/var/www/html/";
$_HTTP_PATH = "http://example.com/";
$_MODULES_PATH = $_SITE_PATH."modules/"
$_MODULES = array(
"datagrid"=>$_MODULES_PATH."datagrid/init.php",
"something_else"=>$_MODULES_PATH."something_else/init.php"
);
Each module would have it's own directory with instantiation init.php so that it would load all it required to get going.
This way you could code as you liked and when you needed something (preferably in the header state) do something like this.
global $_MODULES;
require_once($_MODULES["datagrid"]);
Everything will be easily available as and when required without any variable path issues later down the line.
I'm setting up routes in application.ini, so when I try to access /moved, it displays cont/move. It works but only if I type moved all lower letters exactly like it's setup on the first line. How can I make Moved or moVed or any other letter combination also work? Do I need to do it in Bootstrap to get finer control and how?
routes.test.route = moved
routes.test.defaults.controller = cont
routes.test.defaults.action = move
This is not a wise approach.
URLs are case sensitive for a reason. You will get duplicate content penalty from search engines. Users will be confused too.
However, you may create controller plugin to achieve this:
public function preDispatch()
{
$this->getRequest()->setControllerName(
strtolower($this->getRequest()->getControllerName());
)->setDispatched(false);
}
I've searched Google for a few minutes, and this page (http://joshribakoff.com/?p=29) covers a nice patch. This patch overrides the request object, instead of the dispatcher or the router.