Kohana 3.1 Controllers in Sub Folders within the Controller Folder - kohana-3

I need to create sub folders for my controllers for ease of managing and troubleshooting. I need to have controller/, controller/admin, controller/user/ kind of setup. I have tried creating the controller in controller/admin/createuser from http://mydomain/admin/createuser but that does not seem to work.
Anyone with tips on this?
Do I need custom routing?

You would need to set up a Route to catch /admin/ and look for an 'directory' called admin rather than a 'controller file' called admin.
Then your 'createuser' param would ideally be in a 'user' controller, so 'createuser' would be an action in your users controller
Note the 'directory' declaration -
application/bootstrap.php
Route::set('admin', 'admin(/<controller>(/<action>(/<id>)))')
->defaults(array(
'directory' => 'admin',
'controller' => 'user',
'action' => 'index',
));
Then in your controller you need to use underscores for each directory '/' in the Class name
- application/classes/controller/admin/user.php
class Controller_Admin_User extends Controller {
public function action_createuser()
{
..your code
}

Related

rspec-puppet: cannot find class that is required

So I have a fully functional 'ldap' class.
Now I want to do some stuff for certain users in my ldap directory.
I do this in a new 'users' module, by first making a new defined_type:
define users::admin (
String $sshkey
) {
file {"/home/${title}":
ensure => directory,
owner => $title,
group => 'root',
require => Class['ldap']
}
...
}
Then I use this defined type in my 'users' module's init.pp:
class users {
users::admin {'ldt':
sshkey => 'mysshkey',
}
}
But when I try to use 'pdk test unit' on this, I get the following error:
failed: rspec: ./spec/classes/users_spec.rb:8: error during compilation:
Could not find resource 'Class[Ldap]' in parameter 'require'
(file: ~/Projects/puppet/modules/users/spec/fixtures/modules/users
/manifests/admin.pp, line: 15) on node <mycomputer>
For completeness's sake, here's my admin_spec.rb (barely changed from the pdk default):
require 'spec_helper'
describe 'users::admin' do
let(:title) { 'namevar' }
let(:params) do
{
'sshkey' => ''
}
end
on_supported_os.each do |os, os_facts|
context "on #{os}" do
let(:facts) { os_facts }
it { is_expected.to compile }
end
end
end
I tried setting my .fixtures.yml as follows, but that didn't help:
fixtures:
symlinks:
ldap: "#{source_dir}"
Any idea on what I'm doing wrong?
EDIT: changed my .fictures.yml to:
fixtures:
symlinks:
ldap: "#{source_dir}/../ldap"
Heck I even manually added a symlink to my ldap module in the spec/fixtures/modules folders. Still the same error.
So it turns out the error had nothing to do with rspec or anything.
I just needed to 'include ldap' in my actual puppet code.

how to make sure the file created before class import?

I am fighting with ensuring things are taking place in the order I specified in puppet :( Here is what I plan to do
class A {
notice("1")
file{ 'my file':
force => true,
replace => 'no',
ensure => 'present',
content => "content",
owner => 'me',
group => 'me',
mode => '0444'
}
notice("2")
}
class B {
require A
contain target_class_dependent_on_file
}
then I call the classes as
classA{} -> classB{}
and class B always fails because file is not created, 1 and 2 are output just fine before class B. But if I skip classB, I can see file created just fine. I am banging my head against wall now. Can someone please give me some help? many thanks
nvm. This is not a legitimate case. The 'my file' I tried to set up is really to set up a facter. It will never work

Kohana - one function on every controller

I have a project in Kohana 3.3.
I have a lot of controllers, models etc.
Now, I want add one functionality - close the whole site for all users.
Where I can add function, which for example, will redirect users to http://mypage.com/website_is_close ?
Example:
function check(){
$isClose = DB::query(.....)
if($isClose) header("Location: http://mypage.com/website_is_close");
return false;
}
Thanks :)
In Controller_Base all other controllers extend from. E.g.
File application/classes/Controller/Base.php
class Controller_Base extends Controller_Template {
public function before()
{
$isClose = DB::query(.....)
if($isClose)
{
HTTP::redirect("http://mypage.com/website_is_close");
exit ;
}
parent::before();
}
}
All other classes should extend from that class e.g
class Controller_Home extends Controller_Base {}
I personally use this also for every subdirectory e.g.
// As all controllers in the user folder probably need to be supplied with a user anyway
class Controller_User_Base extends Controller_Base {}
class Controller_User_Profile extends Controller_User_Base {}
I think a better approach would be to add a "catch all" route to the beginning of your routes list.
It would catch all URLs and would point to a controller that you would create. This is far cleaner than hacking away at a base controller.
How does this look?
Route::set('closed', '(<url>)', array('url' => '.*'))
->defaults(array(
'controller' => 'Closed',
'action' => 'index',
));

Symfony2.1 FOSUserBundle overriding validation

i have problems overriding the form validation.
I have overridden the user class and the RegisterFormType class. In the RegisterFormType class i used the setDefaultOptions function to use an other validation group
public function setDefaultOptions(OptionsResolverInterface $resolver) {
$resolver->setDefaults(array(
'data_class' => 'Clickstorm\Geruest\UserBundle\Entity\User',
'intention' => 'register',
'validation_groups' => array('register')
));
}
But when i submit the form the default validation is executed. But what confuses me the most is that when i tried to override the validation by create an own validation.xml file the validation was triggered twice (the error messages where schon twice).
Any idea about that?
I don't know if this is the right solution. But it works when overriding the validation_groups in the config file.

Why can't Kohana find my controller?

I have the following controller:
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Static extends Controller_DefaultTemplate {
public function action_index()
{
View::set_global('message', '<span class="highlight">This is a global message.</span>');
$data = array (
'siteTitle' => 'Kohana Test Site',
'siteSubtitle' => 'A site to learn Kohana',
'menu' => View::factory('blocks/menu'),
);
$view = View::factory('templates/layout', $data);
$this->request->response = $view->render();
}
}
but kohana gives me the error:
ErrorException [ Fatal Error ]: Class
'Controller_DefaultTemplate' not found
although Eclipse can find the file (via F3) and I thought Kohana was able to find all classes via autoloading?
How can I get Kohana to find the Controller_DefaultTemplate class so I can extend Controller_Static?
You must include file with definition of Controller_DefaultTemplate
The problem was that my file name defaultTemplate.php was camel case, changing it to all-lowercase defaultemplate.php enabled Kohana to find the class inside it.

Resources