-
Posts
969 -
Joined
-
Last visited
Everything posted by Destramic
-
<?php class Action { protected $_request; protected $_response; protected $_model; protected $_view; public function __construct(Request $request, Response $response) { $this->set_request($request)->set_response($response)->set_view($request, $response)->set_model(); // if request requires partial then do this $partial = Partial::singleton(); $view = $this->get_view(); $view->set_partial($partial); $partial->set_view(clone $view); } protected function set_request(Request $request) { $this->_request = $request; return $this; } protected function set_response(Response $response) { $this->_response = $response; return $this; } protected function set_view(Request $request, Response $response) { $this->_view = new View($request, $response); return $this; } public function get_request() { return $this->_request; } public function get_response() { return $this->_response; } public function get_view() { return $this->_view; } public function dispatch($method, $parameters) { if ($this->get_request()->is_dispatched()) { if(method_exists($this, $method)) { call_user_func_array(array($this, $method), $parameters); } else { echo "unable to load method"; } } } public function __get($property) { $property = '_' . $property; if (property_exists($this, $property) && $property !== '$this->_request' && $property !== '$this->_responce') { return $this->$property; } return false; } public function set_model() { $class_name = get_class($this); $model_name = trim($class_name, "_Controller"); $model_name = strtolower($model_name); $property_name = '_' . $model_name; $model_name = Inflection::singularize($model_name); $model_name = ucfirst($model_name); $model_class = $model_name . '_Model'; $this->{$property_name} = new $model_class(); } } <?php class View { protected $_variables = array(); protected $_helpers = array(); public function __construct(Request $request, Response $response) { } public function __set($name, $value) { $this->_variables[$name] = $value; } public function __get($name) { return $this->_variables[$name]; } public function __call($name, $parameters) { $helper = $this->get_helper($name); if (!$helper) { $helper = call_user_func_array(array(new $name(), '__construct'), $parameters); $this->set_helper($name, $helper); } return $helper; } protected function set_helper($helper, $instance) { $this->_helpers[$helper] = $instance; } protected function get_helper($helper) { if (isset($this->_helpers[$helper])) { return $this->_helpers[$helper]; } return false; } public function set_partial(Partial $partial) { if ($partial instanceof Partial) { $this->set_helper('partial', $partial); } } public function render($file) { if (preg_match("/\.html$/i", $file)) { require_once PRIVATE_DIRECTORY . 'application' . DS . 'views' . DS . $file; } } } <?php class Partial { protected $_view; protected $_templates; protected static $_instance = null; public static function singleton() { if (self::$_instance == null) { self::$_instance = new self(); } return self::$_instance; } public function set_view(View $view) { $this->_view = $view; } public function __set($name, $options = array()) { $this->_templates[$name]; $this->_templates[$name]['path'] = $options[0]; $this->_templates[$name]['variables'] = $options[1]; } public function __get($name) { // when $this->paertial()->header; is called in view template // it extracts variables and includes template view render() method $file = $this->_templates[$name]['path']; $variables = $this->_templates[$name]['variables']; } } Hey guys im trying to make alternations to my personal framework by adding a Partial class as a helper to the View class so that I'm able to add partial templates in my bootstrap and load accordingly in my view template like a header and footer. what im after is a bit of advise on the functioning of my Action/View and Partial please (not sure if what im doing is really right although it does work) Basically my Controller will extend my action where a model and view is made for my controller to use. Then my partial class is sent as a helper to my view and a clone of view sent to my partial so that im able to use the view class in my partial to render my header and variables. (is this the correct way? or a good method?) here's my code...like I said any advise would be greatly appreciated... thank you
-
thank you guys...really helpful specially with the shapes example...although one more question on that topic of inheritance, im currently using my News_Controller to extend my Action...would that be the correct way of doing things?
-
well I have a News Controller were all my actions are...the News Controller extends Actions and Actions extend View why how should it be...any pointers will be great
-
the problem im getting doing it like that is that is adds as a variable on the view subclass on __set...which then allows it to be accessible in my header.html =/ is there a away around this?...without setting a property above like $_model? thank you
-
self::${$attribute_name} = new $model_class(); doesn't work =/
-
I've been fiddling about and changed the property exist search from $this to __class__ then if not i'll load it from the parent although im having trouble with setting the model...I want to set it to self:: if possible public function set_model() { $class_name = get_class($this); $model_name = trim($class_name, "_Controller"); $model_name = strtolower($model_name); $attribute_name = '_' . $model_name; $model_name = Inflection::singularize($model_name); $model_name = ucfirst($model_name); $model_class = $model_name . '_Model'; self::$attribute_name = new $model_class(); }
-
when I set my model It will be available in my as a view var which isn't what you want in a framework?...it would then be able to be accessed in my templates
-
Here are my class files but yeah basically my __get method in my action class conflicts with the view class...is there anything I could do to get around this? <?php class Action extends View { protected $_request; protected $_response; protected $_partial; public function __construct(Request $request, Response $response) { $this->set_request($request); $this->set_response($response); $this->set_model(); } protected function set_request(Request $request) { $this->_request = $request; return $this; } protected function set_response(Response $response) { $this->_response = $response; return $this; } protected function get_request() { return $this->_request; } protected function get_response() { return $this->_response; } public function dispatch($method, $parameters) { if ($this->get_request()->is_dispatched()) { if(method_exists($this, $method)) { call_user_func_array(array($this, $method), $parameters); } else { echo "unable to load method"; } } } public function __get($property) { $property = '_' . $property; if (property_exists($this, $property)) { if ($property !== '$this->_request' || $property !== '$this->_responce') { return $this->$property; } } } public function set_model() { $class_name = get_class($this); $model_name = trim($class_name, "_Controller"); $model_name = strtolower($model_name); $attribute_name = '_' . $model_name; $model_name = Inflection::singularize($model_name); $model_name = ucfirst($model_name); $model_class = $model_name . '_Model'; $this->$attribute_name = new $model_class(); } } ?> <?php class View { protected $_request = null; protected $_variables = array(); protected $_helper = array(); public function __construct(Request $request) { $this->set_request($request); } public function __set($name, $value) { echo $name; $this->_variables[$name] = $value; } protected function set_request(Request $request) { $this->_request = $request; } public function __get($name) { return $this->_variables[$name]; } protected function get_request() { return $this->_request; } public function __call($name, $arguments) { $helper = $this->get_helper($name); if (!$helper) { $helper = call_user_func_array(array(new $name(), "__construct"), $arguments); $this->set_helper($name, $helper); } return $helper; } protected function set_helper($helper, $instance) { $this->_helper[$helper] = $instance; } protected function get_helper($helper) { if (isset($this->_helper[$helper])) { return $this->_helper[$helper]; } return false; } public function render($file) { if (preg_match("/\.html$/i", $file)) { require_once PRIVATE_DIRECTORY . 'application' . DS . 'views' . DS . $file; } } } ?>
-
I have two classes were one extends the other but they both have magic methods __get __call and __set but when trying to call a magic method it conflicts one with the other as you can imagaine...is there a way of getting around this ie. name spaces or do I simply have to rewrite my classes thank you
-
@requinix thanks, that will work quite nicely
-
is there a way of having set variables for a specific include?...maybe be easier for me to explain via code <?php $bee = 'yes'; include_one "a.php"; include_one "b.php"; // only b.php can grab $bee var ?> im wondering if I can only pass a var to b.php without a.php being able to use the var also? thanks guys
-
but that way im gonna have 2 entries of the same item one in Arabic and one in English...not really what I was after unless I somehow have a translation table possibly
-
basically im going to require 2 variations of the same item and its columns but in two different languages...ummm
-
I'm developing an arabic site...but also want to view it in English...I'm thinking of using windows translating service (depending on good it is). Now I was thinking of having columns in my table like so...english title, arabic title, english description, arabic description As it can charge for words to be translated...when translating arabic to english I can store the results in the column so they would no longer have to be translated again My question is...is it good practice to have separate columns for different languages?...thank you...any input would be great
-
But using utc_timestamp would be good practice incase server isn't British as phyco said...thank you for your help guys...much appreciated
-
Putting it like that it sounds like a near impossible task...specially with languages ever growing...but that you for your example...any solutions and where one would go from here?...just use Google translate?
-
str_replace("?,","", $var); I want to replace it with nothing...just want to remove any one of the matching characters...but I'm unaware of the regex syntax I need thank you
-
when trying to decode a array of rows taken from my database I found that the json_encode function doesn't allow you to present you array as (with brackets [ ]) [{"name":"Destramic"}] but returns the array as (without brackets [ ]) {"name":"Destramic"} I looked into the documentation and it doesn't seem as if php offer such a way of having bracket which Is a bit of a problem with passing to jquery (which I've found using their autocomplete plugin) this has resulted in me having to add brackets myself $data = "[" . json_encode($rows2) . "]"; does anyone know if you can encode it with the brackets or readable for jquery...thank you
-
well I'm not here to fool myself but I know a person who is speaks both languages so I'm thinking on the lines of him translating possibly
-
hey guys im after the pattern to replace , and & symbols please?...any help would be great thank you
-
@davidvannis looking good...although the problem with Google translate I.find it's pretty crap...due to some of the times words don't translate correctly...at lot of reading for me I guess...although I could findu someone who knows english and arabic
-
I apologise admin for multi posts :/
-
Hey guys I'm after a English to Arabic translation script...although I have Googled it but as you can imagine there's no script of that. Would I have to create a array of English words and then give them the value in Arabic? :/...just wondering if I have any other options...thank you
-
I apologies for my slowness in digesting this information haha...well I've come to theory that when all data is added to the database then I will use the UC_TIMEZONE() function when selecting the information I could use ? CONVERT_TZ(created, UC_TIMEZONE(), America/Akta) please tell me I've got it haha :/
-
Ok let me clarify a few things please (sorry)...so when inserting data I set time zone in the query to Europe/London...then when selecting I set the timezone to the user's timezone preference so that when I return the timezone column from my row it would convert to the user's preference? :/