PHP - What Framework Do I Use?
I wirte php... do i use a framework?.. if so what framework do i use?...
When i do phpinfo(); ... i get a screen that says: This program makes use of the Zend Scripting Language Engine: so do i use the zend framework? regards J Similar TutorialsThis topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=347122.0 Hi, I have been doing small scale programming but I am now planning to foray into large scale, intensive web application to handle high traffic, definitely I need something fast, efficient and re-usable. Since I am programming for a while, I have my own collection of code which I use for base and generally am able to build fast and secure (small) web application. But now I am looking into framework. So, here is the question.. Should I look into framework like Yii , Kohana etc.. or Should continue building on my own code .. I just don't want to learn all those framework if and but then at the decides not to use them as I find them not really helpful !!! Hi, I'm trying to write my own php mvc framework, but I don't know where to start. I have been using codeigniter for a while, then i thought i shouldn't use it, because I'm not getting smarter when most of the code is written for me. So, writting my own framework would be a great practice to learn oop, i guess. I need: url routing, the would work like codeigniter's (http://website.com/controller/method/some/other/params) and calling some function for rendering layout files similar to codeigniter's ($this -> load -> view ( 'file.php' ); and not like this: $header = new Template ( 'header.php' ); then some coding with header, and same with content.php and footer.php). Can anyone please help me? Where to start? sorry for bad English hey guys im after a bit of advise on routing within my framework please.
now i've created a route:
account/verify/email-address/:email_address/activation-key/:activation_key
which will be then interpurated into
account/verify/email-address/destramic-at-hotmail-dot-com/activation-key/12345
now my question is having a email address in a url is good idea?
if so i can decode the :email_addres parameter in the route like so:
$router->add_route('account/verify/email-address/:email_address/activation-key/:activation_key', array('controller' => 'users', 'action' => 'activate_account', 'decode' => 'email_addres' => 'string_to_email') ));would like your thoughts on this please guys (go easy)...if not a user_id would be sufficient i suppose thanks hey guys im having a bit of trouble getting $_GET in my framework. now the ony way to get query from a url such as:
users/activate-account?email_address=test&token=test
i have to use $_SERVER['REQUEST_URI'] unless im doing something wrong?
[REQUEST_URI] => /bisi/user/activate-account?email_address=test&token=test
by doing this:
print_r($_GET);all i get is : Array ( [uri] => user/activate-account ) just concerned im doing something wrong?...any advise on this please guys. was thinking of doing something like this in my request public function get_query($name = null) { $uri = $_SERVER['REQUEST_URI']; if (parse_url($uri, PHP_URL_QUERY)) { $query = explode("?", $uri); $query = explode("&", $query[1]); $array = array(); foreach ($query as $string) { $string = explode("=", $string); $query_name = $string[0]; $query_value = $string[1]; $array[$query_name] = $query_value; // $_GET[$query_name] = $query_value; possibly? } if ($name !== null && array_key_exists($name, $array)) { return $array[$name]; } return $array; } return null; }thanks Lol! Ok let's see... index.php <?php /* index.php this file will be under /var/www/site/public_html or some other public dir */ //this will look into ../application //you can do something like /var/www/site/application if you want define("APP_PATH", __DIR__ . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "application" . DIRECTORY_SEPARATOR); define("LIB_PATH", APP_PATH . "lib" . DIRECTORY_SEPARATOR); //This is because we don't want direct access to files, we'll be checking in every private file //if this is defined define("O_FRAMEWORK", "Bla bla bla"); //Had to make theese variable because i had some problems with the require_once when using constants + strings, i'll fix this soon $config_path = APP_PATH . "config.php"; $router_path = LIB_PATH . "Router.php"; $front_path = LIB_PATH . "Front.php"; require_once($config_path); require_once($front_path); require_once($router_path); if(isset($autoload)){ if(!autoload($autoload)){ echo "zzz"; exit(); //Errors when trying to open files... } } $router = new Router(); if($router->isRouteValid() == false){ echo "404"; exit(); //Didn't find route } $front = new Front(); $front->servePage($router->getRoutePath()); //This part of code should probably be optimized... function autoload($autoload) { for($i = 0; $i < sizeof($autoload); $i++){ if(!file_exists(APP_PATH . $autoload[$i] . ".php")) return false; require_once($autoload[$i] . ".php"); } return true; } ?> Front.php <?php /* Front.php Ok hm... this is very uncomplete :/ */ if(!defined("O_FRAMEWORK")){ echo "Direct file access forbidden"; exit();} define("CONTROLLER_PATH", APP_PATH . "controllers" . DIRECTORY_SEPARATOR); class Front { public function __construct(){} public function servePage($routePath) { if(strpos("/", $routePath)){ //Will do this later :P } else { $controller_name = $routePath; $method = "index"; } require_once(CONTROLLER_PATH . $controller_name . ".php"); $controller = new $controller_name(); $controller->$method(); } } ?> Router.php <?php /* Router.php */ if(!defined("O_FRAMEWORK")){ echo "Direct file access forbidden"; exit();} class Router { private $_route; private $_available_routes = array ( "Homepage" => "/", ); private $_route_path; public function __construct() { $this->_route = $_SERVER["REQUEST_URI"]; } public function getRoute() { return $this->_route; } public function getRoutePath() { return $this->_route_path; } public function isRouteValid() { foreach($this->_available_routes as $route){ if($this->_route == $route){ $this->_route_path = array_keys($this->_available_routes, $route, true); $this->_route_path = $this->_route_path[0]; return true; } } return false; } } ?> config.php <?php //This is empty atm ?> Homepage.php (this is the home controller) <?php if(!defined("O_FRAMEWORK")){ echo "Direct file access forbidden"; exit();} class Homepage { public function __construct(){} public function index() { echo "Homepage"; } } ?> This is what i got, it's all messed up but i'll fix it soon Okay, this is a head scratcher for me... About 10-15 years ago, there was this framework that seemed to be pretty popular in the LAMP work for quickly building websites. (I think it was written in PHP.) The thing I recall about it was that it you could create your own markup tags to markup up fields using curly brackets { }. I wish I could be more specific but this is all that is coming to mind. Any clues of what I might be thinking about? Hi, I am going to start a project which would be like a single page site, sending requests from one page and displaying result on same page. I would like to know which framework would be better. here i see top 10 frameworks http://www.phpframeworks.com/top-10-php-frameworks/ any suggestion please? Thanks Hello guys, okay? Hi guys
I am a php programmer and in a big confusion. I want to learn a framework, but can't figure out which one start ?
CakePHP
Codelgniter
Symfony
laravel
I am new to them, so you can suggest me which one to start 1st and move on to other. Or If i miss any other framework , you can tell me that also.
Any help is appriciable.
Thanks
<?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 I know this question sounds a bit vague. I have not been working with php too long, maybe 6 months or so. I have worked with other programming languages and do have a good grasp of OOP. I have a few ideas for some apps I want to make, nothing that will be the next commercial hit. I just to do some php apps to get better at php. Everywhere I look some one is talking about a framework, and it looks like Codeigniter seems to be everyones fave, despite the fact that there is a good chance it will die out soon. I ended up giving Codeigniter a try and although I understand MVC, and I get OOP, and all of that, it seems there are many ways to set things up and a lot of the tutorials I tried out had different ways to do things withing Codeigniter, the problem with that is some of the stuff I learned on tutorials I could not get to work on my set up. I got frustrated and simply gave up after a while of tinkering with CI. I know there are plenty other frameworks, but I am wondering if I will truly be at a disadvantage if I just write core php with out using a framework.
Thanks if advance for the input.
Just wondering how many people recommend using a framework, such as cakePhp, or coding from scratch? I always coded from scratch, but tried using a Php framework recently called Elgg. It was an absolute nightmare. so how many code from scratch? and how many people use a framework? I am new to mvc , I have down loaded frame work from http://www.php-mini.com
//CONTROLLER
public function upload_slider(){ My next project is going to be upgrading my jobs database/stock management software from windows PC based software, to web-based. Even though I am typically a windows-based programmer, I have decided to use PHP for this project. Hi everyone, first thanks for caring to read my post! I am very very new to php but have a really good idea for a site so thought this could be a good chance to finally learn. The site is basically going to be a simple yet very well structured and organised repository for articles with the ability for users to post comments at the bottom of each article (logged in users). The users can also post articles and select which sections they want to put them in. The admin could then review all submissions and accept and then put them in the order in which they best fit (since the articles will usually be relevant to different stages and should be placed in order of assumed knowledge, if that makes sense) Kind of like a tutorials site with content being submitted. I imagine a really uncluttered site that looks more old school than web 2.0. From the first page is just like a simple search engine and underneath a kind of sitemap with each topic showing how many articles are in each. Then as you click into the topic area you are shown another sitemap like display of the articles in this which are perhaps some sectioning to define the type of article it is. As I say, I am quite new so I wondered if you had some suggestions of the top 'aids' to achieving this, and how you would suggest I progress to get it all setup? Or indeed any frameworks already that fit my needs? I hope to be active here and look forward to being to give something back some day. Edit: after reading this through,, I realise I just described a kind of wiki, but thats not really what I had in mind- more just how the old school basic but very clean and functional sites were back in the day (meaning no disrespect to any of the newer ones!). Thank you for reading. So I am working on my own PHP framework and I am using this:
php_value auto_prepend_file library/fw.php php_value auto_append_file library/fw.phpTo auto prepend and append file. In that file I have check if instance of core class located in fw.php is defined so it will not prepend and append duplicates. With this I reduced index.php code by these 2 lines // This should be at beggining of index php $fw = Base::getInstance(); // This should be at very end of index.php $fw->run();Is it good or bad way? I have spent the last few days going over Zend framework 2, and I am finding it extremely complex. Not saying it shouldn't be, but it seems to solve problems I never have come across (so to speak) .
For instance:
Routing is super complex. I usually use torophp - which is simple & gets the job done.
Dependency injection - example of problem I have never come across.
My motivations for learning zend, are -
1. To write modular reuseable code.
2. Learn advanced / modern PHP , as far as frameworks are concerned I just know codeigniter.
3. A framework with good long term support.
Is there some other framework that is easier to learn ? and that would satisfy my requirements ?
I have been programming in PHP for the last 2-3 years btw, so I know my way around
Thanks
Edited by nik_jain, 31 August 2014 - 09:56 AM. This topic has been moved to Application Design. http://www.phpfreaks.com/forums/index.php?topic=327717.0 |