I'm using CakePHP 2.3.1.
Our server has some independent applications in one server. So I want to change session.cookie_path setting following the Cookbook :
Configure::write('Session', array(
'defaults' => 'php',
'ini' => array(
'session.cookie_path' => '/app/dir'
)
));
I could change it successfully with this. But here is a problem. I need to set session.cookie_path value to webroot dynamically (without string literal value such as '/app/dir').
I've tried to use $this->webroot following this Q&A, but of course it does not work because there is no controller in the file app/Config/core.php.
Any ideas?
I realized a php variable is available : $_SERVER['REQUEST_URI'].
So I could solve the problem.
$requestURI = $_SERVER['REQUEST_URI'];
$webroot = preg_replace('/(^\/[^\/]+\/).*$/', '$1', $requestURI);
//echo $webroot;
Configure::write('Session', array(
'defaults' => 'cake',
'ini' => array(
'session.cookie_path' => $webroot // looks like '/app/'
)
));
But this solution does not have reusability enough : it would not work for apps located in deeper directories such as /apps/app1/.
I'm still awaiting a better solution.
Related
i am creating a plugin with plugin hooks when plugin activate it creating product attributes it working fine also i adding attributes terms it also working fine and on plugin deactivate i am deleting it but i see only attributes deleting but terms not delete.
i using this code for deleting attributes it working fine
enter code here
// attributes parameters
$wpm_attributes = array(
array(
'label' => 'Size',
'name' => 'size',
'type' => 'select',
),
array(
'label' => 'Color',
'name' => 'color',
'type' => 'select',
)
);
foreach ( $wpm_attributes as $attr ) {
$attribute = array(
'attribute_label' => $attr['label'],
'attribute_name' => $attr['name'],
'attribute_type' => $attr['type'],
'attribute_orderby' => 'menu_order'
);
$wpdb->delete( $wpdb->prefix . 'woocommerce_attribute_taxonomies', $attribute );
delete_transient( 'wc_attribute_taxonomies' );
}
I recommend not deleting the terms at the point of deactivation.
Instead why don't you delete the terms at the point of uninstallation?
You can use the uninstall hook:
http://codex.wordpress.org/Function_Reference/register_uninstall_hook
Or bypass that.
The plugin should create a file named 'uninstall.php' in the base plugin folder. This file will be called, if it exists, during the uninstall process bypassing the uninstall hook.
This may be easier to manage code wise and sometimes people would like to deactivate a plugin and not lose all their data.
This question is regarding Zend Framework application version: 2.1.3. I, the developer, am new to Zend Framework and would greatly value your assistance.
I was making a module for a 'Donor Management System' of a church. The module I am working on is called the 'QueryBuilder'. Previous modules were fine and works great. I use the Zend Helper for Sublime Text and it generated some thing similar for the module.config.php
<?php
/**
*
* #package QueryBuilder
*/
return array(
'controllers' => array(
'invokables' => array(
'QueryBuilder\Controller\QueryBuilder' => 'QueryBuilder\Controller\QueryBuilderController',
),
),
// The following section is new and should be added to your file
'router' => array(
'routes' => array(
'querybuilder' => array(
'type' => 'segment',
'options' => array(
'route' => '/querybuilder[/:action][/:id]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'controller' => 'QueryBuilder\Controller\QueryBuilder',
'action' => 'index',
//'action' => 'search',
//'action' => 'recent',
),
),
),
),
),
'view_manager' => array(
'template_path_stack' => array(
'querybuilder' => __DIR__ . '/../view',
),
),
);
?>
Determined to have a little bit of fun after making some successful modules, I changed the router as follows.
<?php
/**
*
* #package QueryBuilder
*/
return array(
'controllers' => array(
'invokables' => array(
'QueryBuilder\Controller\QueryBuilder' => 'QueryBuilder\Controller\QueryBuilderController',
),
),
// The following section is new and should be added to your file
'router' => array(
'routes' => array(
'querybuilder' => array(
'type' => 'segment',
'options' => array(
'route' => '/query-builder[/:action][/:id]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'controller' => 'QueryBuilder\Controller\QueryBuilder',
'action' => 'index',
//'action' => 'search',
//'action' => 'recent',
),
),
),
),
),
'view_manager' => array(
'template_path_stack' => array(
'querybuilder' => __DIR__ . '/../view',
),
),
);
?>
Note: Only the route value was changed from /querybuilder... to /query-builder.... When I tried to access the route http://konnections/query-builder I got some error but I didn't go through it.
Wondering why I wan't to be a hero, I changed the value back to its defaults. And tried to load http://konnections/querybuilder but it also gave an error.
Zend\View\Renderer\PhpRenderer::render: Unable to render template "query-builder/query-builder/index"; resolver could not resolve to a file
No where in the code of the module you could find the words query-builder. So common sense says there can be no way query-builder/query-builder/index needs to be accessed.
Thinking it might be some caching, I looked for it in the entire application folder. Then I restarted Apache, the computer, deleted and made a new Module with the same name QueryBuilder and still the error is there.
Note: This is a plugin that was done nothing with. I only changed the route value thinking it will make the URL look neater.
Here is what I end up with [Image]:
Nope, this is not IE, because I tried in Chrome (which didn't access the query-builder url) as well.
The whole of Zend Folder (the root of the website) has no reference to query-builder. Where does it come from and how can I change it?
Thanks in advance.
from ZF1 series (http://framework.zend.com/manual/1.12/en/zend.controller.basics.html), ZF2 is the same but not found this description on manual.
Case Naming Conventions
Since humans are notoriously inconsistent at maintaining case sensitivity when typing links, Zend Framework actually normalizes path information to lowercase. This, of course, will affect how you name your controller and actions... or refer to them in links.
If you wish to have your controller class or action method name have multiple MixedCasedWords or camelCasedWords, you will need to separate those words on the url with either a '-' or '.' (though you can configure the character used).
As an example, if you were going to the action in FooBarController::bazBatAction(), you'd refer to it on the url as /foo-bar/baz-bat or /foo.bar/baz.bat.
I am Ziyan, the one who asked the question in the first place.
After not finding a solution in Google, I wondered in to making another module and ended up with the same plight. Confused I made a new installation of Zend Framework and made a module with the same name.
Zend\View\Renderer\PhpRenderer::render: Unable to render template "query-builder/query-builder/index"; resolver could not resolve to a file did not go away.
Knowing it is not some thing like reconfiguration, I looked closer.
It seemed to put a dash between every word. I was like Zend is insane! But no, it seems to be splitting the Module name from each upper case letter and adjoining them using a '-' (dash).
In my case QueryBuilder becomes query-builder or plugin named HelloModules would be hello-modules.
So the view manager seems to be looking for ../views/query-builder/query-builder/index.
In my case, ZF Helper for Sublime text needs to look in to the situation. If you could fix the plugin at GitHub it would be great. I will give a try my self.
I couldn't find any proof for my claiming and no time to go through the source codes. Would be glad if some one provide some links.
I have one database - (users, administrators).
I have 2 app. (application/login, backend/login).
So, when I log in at "backend" with my administrator data, I don't want to be logged in with that SAME data on "application".
How can I get two different sessions for two different applications in CakePHP under the same browser?
I want to be logged in with administrators under /backend and with user under /application.
CakePHP 2.2.0.
Thank you all. :)
Solved it. In app/Config/core.php:
Application:
Configure::write('Session', array(
'defaults' => 'cake',
'ini' => array(
'session.cookie_path' => '/application',
),
'cookie' => 'my_cookie',
));
Backend:
Configure::write('Session', array(
'defaults' => 'cake',
'ini' => array(
'session.cookie_path' => '/backend',
),
'cookie' => 'my_cookie_2',
));
Thanks anyway. :D I've learned a lot in this few hours. :D
All,
I currently have slug setup in my app where I generate the following as links:
http://www.domain.com/article/my-first-news-article.
And this is the current route that I use to accomplish that in addition to the view acepting a slug instead of id:
Router::connect('/article/*',array('controller' => 'articles', 'action' => 'view'));
However, I wanted to improve that a little bit more by adding published date to the URL like the following:
http://www.domain.com/article/2012/06/27/my-first-news-article
I have the following code from the CakePHP manual, but it doesnt seem to work:
Router::connect(
'/article/:year/:month/:day/:slug',
array(
'controller' => 'articles',
'action' => 'view'
),
array(
'year' => '[12][0-9]{3}',
'month' => '0[1-9]|1[012]',
'day' => '0[1-9]|[12][0-9]|3[01]'
)
);
For the sake of this, I really dont care what date is passed to the view. I just care about the slug that is passed. Then I will use function view($slug) to find the article and display it. However the URL needs to be http://www.domain.com/2012/06/27/slug-slug-slug
Thank you....
How do the $this->Html->link() calls look like in the places where you want to use the date in the link?
Are you adding the required params there?
$this->Html->link('Article', array('year' => 2012, 'month' => 01, 'day' => 01, 'action' => 'view', 'slug' => $article['Article']['slug']));
For the sake of completeness, and because somebody else might be interested in this as well, I'll show you my solution to a similar problem:
I want to have URLS in the format
http://mydomain.com/blog/2012/06/slug-slug-slug
i.e. /blog/yyyy/mm/slug
For this, I use
// view a post by year and month and title
Router::connect('/blog/:year/:month/:title/*', array(
'controller' => 'posts',
'action' => 'view'
), array(
'year' => '[12][0-9]{3}',
'month' => '0[1-9]|1[012]',
'title' => '[a-z0-9-]+'
));
With the rules below, you can make sure the correct formats are entered. It also prevents users from entering values such as &"% as slugs.
The /* after title even allows for additional parameters, e.g. for pagination, when your blog entry has several pages (http://mydomain.com/blog/2012/06/slug/page:2).
I also realized that setting the "pass" array is not really necessary (at least in CakePHP 2.0). You can access the parameters directly via $this -> request -> params['year'], etc.
After more research and trials I was able to figure it out.
The following route will work to accept a URL like this:
http://www.mydomain.com/article/2009/06/10/my-first-article-in-mydomain-dot-com.
As a matter of fact, it doesnt actually matter how the date is setup and it will still work. It could also be,
http://www.mydomain.com/article/06/10/2012/my-first-article-in-mydomain-dot-com
Router::connect(
'/article/:year/:month/:day/:slug',
array(
'controller' => 'articles',
'action' => 'view'
),
array(
'pass' => array('slug')
)
);
Just for organization sake, I wanted to use a different table for the authentication component to check, but it doesn't quite work. While I can initially state:
$this->Auth->userModel = "CoreUsers" plus set the loginAction to my proper MVC
works to look at that table just to confirm it's there, but the login doesn't work, it only keeps returning an incorrect password. Something happens in the authentication component; I can't tell what makes it fail. When I rename my table to "Users", it works.
The other part is I'd prefer to actually use the column name of 'email' rather than 'username' since that's really what I'm using anyway.
I am just not having luck finding a complete tutorial and reference sets to do both these successfully with CakePHP 2.x. What is the way forward?
References:
Stack Overflow question How do I use a table other than "Users" for CakePHP's AuthComponent?
Stack Overflow question CakePHP - 'AuthComponent' with a different model name (not 'User')
(I had a look for answers, but I never quite got the whole answer.)
Make sure your database table "core_users" and model "CoreUser" exists.
When you setup component you can put login/logout redirect here.
var $components = array(
"Auth" => array(
'loginRedirect' => array('controller' => 'dashboard', 'action' => 'index'),
'logoutRedirect' => array('controller' => 'core_users', 'action' => 'login')
),
"Session");
Now in beforeFilter medhod you can put the following
function beforeFilter(){
$this->Auth->authenticate = array(
AuthComponent::ALL => array('userModel' => 'CoreUser', 'scope' => array("CoreUser.status" => 1), "fields" => array("username" => "email", "password" => "your_password_field"), 'Form', 'Basic'
);
}
Above example you can ignore status, if you need to pass any other info on the login verification u can use that. Now about you can remove 'Basic' if you only need form validation.
I hope this would work .
First, model names are generally singular. Are you sure you didn't mean CoreUser which would look in the core_users table?
Secondly, you can use the email field instead of username by setting the fields key on your auth setup.
public $components = array(
'Auth' => array(
'authenticate' => array(
'Form' => array(
'userModel' => 'CoreUser',
'fields' => array('username' => 'email')
)
)
)
);
See the book for more information.