kohana

What is a good approach on dealing with repetitive and lengthy validation codes?

I have only recently started web programming and I am pretty much amazed that although I am using a validation library, I still get 20-30 lines of code for validation alone, not counting error messages and callback functions. I am using the Kohana MVC framework and I was wondering if there was any way I can shorten my validation codes. I...

Proper way for count empty variables

Hi, I use kohana and when you try to fetch data from database it returns class variables(like $user->firstname) as a database data. User table have a 12 columns and i fetch 8 columns but at this point some of columuns maybe empty(like $user->phone). How can i found empty column number ?(Proper way..) Thanks A Lot ...

Help with PHP method_exists()

Hi I am writing a "catch all" method for my controller for ajax. It is called 'ajax' :P This is what it currently looks like public function ajax($method = null) { if ( ! $method OR ! request::is_ajax()) { return false; } if (method_exists(array($this, 'searchModel'), $method)) { echo $this->searchMode...

How to show conditional data in views in MVC frameworks?

How do people generally handle conditional statements in MVC frameworks For some of my pages (made under Kohana) I want the user to have more options depending on whether they are logged in or not, and whether the profile is their own profile for example. From your own experience, do you create separate views, empty variables, do the l...

default timezone error in php

I got the following error/warning while tring to install Kohana/SilverStripe.What does it mean and What do I do for it? Warning: date_default_timezone_get(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of t...

How do I deal with an occassional 302 HTTP error

I have read that 302 HTTP errors are not supposed to appear frequently even if you do receive one of them. the problem is they appear one out of 10 times in a page redirect in my script. Have you had any experiences with this before? I am using a PHP framework called Kohana. ...

Calling a controller within a controller?

As far as best practices go is this recommended? I have a comments controller + model that needs to be called in an items and profiles controller. The comments controller automatically loads the comments model. Is it acceptable to call the comments controller directly from the items and profile controller, or is the "best practice" way ...

How to enforce URI segments to Kohana pagination after the page URI segment?

I'm using Kohana's pagination library and it lets you specify the parameter uri_segment at initialization. When it generates the pages links, they will have that uri_segment you specified, and after that, the page link. Let's say: /some/uri/segments/6 where 6 is the page. Now, that enforces the page number to be the last uri segment. W...

MVC Object Oriented Techniques - How to minimise queries and maintain flexibility?

Hello there I am using an objected oriented MVC framework in PHP (Kohana) and have kind of mashed together a few techniques to get stuff done. Problem is I am not sure how to keep things clean without calling lots and lots of queries per page. To illustrate my example, I'll imagine I am designing a stack overflow like site: I have ...

Separating SQL, PHP and the view when listing categories and products in Kohana

I want to migrate to Kohana with my small websites and I'm trying to separate the SQL, PHP and the view, but I've some problems with this one. I have to tables. Every category can have multiple products. Categories table id category Products table id category_id product This was my previous code (converted to Kohana's query bui...

Namespace or something else to avoid name conflict with Kohana's Image library

I have a custom helper whose class name, Image_Core conflicts with Kohana's Image Library ( I can use the Library anywhere except inside my helper ) Is there any other way to call the Image Library, like a namespace or something? ( well, it isn't in a namespace, as I just checked ) or will I have to rename my helper? Thanks! NOTE: n...

Can I use Mysqli and php5 syntax with Code Igniter?

Im starting a new web project, and I figured I'd try using a framework. I know CI is coded in php4... but will I be able to use the mysqli functions of mysql, as well as php5 syntax (when it comes to OO especially) while coding for CI? Or would I have to go with Kohana? ...

Where should form validation occur in a MVC project?

I'm using Kohana, but I think this question is more general. I have been doing form validation in the controller, and it has worked well so far. But lately, I've ran into a problem. I have a comments model, and I send comments from a few different controllers to it. Instead of having a validator in every controller, I placed it in the ...

Binding params with Kohana's Database library

I know I can bind params in Kohana like this $this->db->query('SELECT * FROM products WHERE id = ?', array(14)); But is there a way to do it with identifiers (or whatever they are called?) As in $this->db->query('SELECT * FROM products WHERE id = :id', array(':id' => 14)); Thanks ...

kohana transaction with orm

is it possible (how) to use mysql transactions and rollbacks using kohana ORM ? ...

script access via permissions

how do I restrict access to scripts using a permission scheme? I have thought of the ff: store permissions as arrays with keys in the power of 2 (2, 4, 8, 16) and use bitwise operators to compare user permissions with permissions required to access the script store permissions as strings and assign a set of permissions to a script. if ...

practical callback functions

How can callback functions help me in my development? Especially with PHP. I am new to php and to programming itself but I saw the power of callbacks in js libraries like jquery. I have worked with a callback in php but I was left asking a lot of questions about it: what is the scope of a callback function what parameters can I pass to...

Kohana: setting the template name dynamically

Perhaps I'm just missing a basic OOP idea in PHP, but for the life of me, I can't seem to set the "$template" variable dynamically. If I extend the Template_Controller, I can set the template name like this: public $template = 'template_file_name'; But I can't set it dynamically like: public $template = $this->setTemplate(); or ...

urls with item title

I was used to putting id's in the URL to map to an item in the database: /hotels/1 but what if I want to get the name of the hotel with an id of 1 and put it in the URL and replace spaces with hyphens? /hotels/hotel-bianca I am using Kohana and there is the concept of routing (which is pretty much present in all MVC frameworks), but ...

Kohana & Form Helper - Default Value in Dropdown

$x=array('a','b','c'); echo form::dropdown('test', $x, 'b'); I'm using the Kohana form helper to build forms, but I've hit a snag. The above test code doesn't display the default value as it should, as written in the docs. Ideas? ...