PHP Debugging in Netbeans

Standard

I have been trying to use php debugging feature of netbeans. I tried it before but did not get it to work.

But this is how i did it.

I installed Xdebug on a Fedora 20 in order to use it with netbeans 7.4.

Install Xdebug:

sudo yum install php-pecl-xdebug.x86_64

Add this lines to php.ini at the end of the file:

sudo vi /etc/php.ini

zend_extension=/usr/lib64/php/modules/xdebug.so
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000

Add the same lines to xdebug.ini file:

sudo vi /etc/php-zts.d/xdebug.ini

xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000

Allow port for Xdebug

sudo semanage port -a -t http_port_t -p tcp 9000

Now find your netbeans.conf file in your system:

sudo find / -name netbeans.conf

Now, open up the file and add the text “-J-Dorg.netbeans.modules.php.dbgp.level=400? in netbeans_default_options so that the line looks somewhat like this:

netbeans_default_options="-J-client -J-Xss2m -J-Xms32m -J-XX:PermSize=32m -J-Dnetbeans.logger.console=true -J-ea -J-Dapple.laf.useScreenMenuBar=true -J-Dapple.awt.graphics.UseQuartz=true -J-Dsun.java2d.noddraw=true -J-Dsun.zip.disableMemoryMapping=true -J-Dsun.awt.disableMixing=true -J-Dnetbeans.extbrowser.manual_chrome_plugin_install=yes -J-Dorg.netbeans.modules.php.dbgp.level=400"

Restart both NetBeans IDE and apache:

sudo systemctl restart httpd

and there you go.

Simple App with AngularJS and Laravel 4

Standard

This is my first attempt of making a simple Web Application using Angular JS and Laravel 4.

I will not go into much detail about Laravel 4 in this post.

So without further ado, here is what i did.

I created a resource controller by using

php artisan controller:make NewsController

In the index() method i just returned all the News items

public function index()
{
return News::all();
}

The show() method looks like this.

public function show($id)
{
return News::find($id);
}

I added following routes in my routes.php file.

Route::resource('news', 'NewsController');

Route::get('shownews', function(){
return View::make('news');
});
Route::get('shownews/{id}', function($id){
return View::make('news-detail')->with('id',$id);
});

I created a View called news.php. (It is not a blade template)


<head>
<title>Learning AngularJS</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js" type="text/javascript"></script>
<script src="<?php echo asset('/js/app.js'); ?>" type="text/javascript"></script>
<script src="<?php echo asset('/js/newscontroller.js'); ?>" type="text/javascript"></script>

</head>
<body>
<div id='content' ng-app="NewsApp" ng-controller="NewsController" ng-init="init()">
<ul>
<li ng-repeat="news in results">
<p><a href="<?php echo url('news/show');?>/{{news.id}}">{{news.title}}</a></p>
<p>{{news.description}}</p>
</li>
</ul>
</div>
</body>

and news-detail.php


<!DOCTYPE html>
<head>
<title>Learning AngularJS</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js" type="text/javascript"></script>
<script src="<?php echo asset('/js/app.js'); ?>" type="text/javascript"></script>
<script src="<?php echo asset('/js/newscontroller.js'); ?>" type="text/javascript"></script>

</head>
<body>
<div id='content' ng-app="NewsApp" ng-controller="NewsController" ng-init="detail(<?php echo $id; ?>)">
<ul>
News
<li ng-repeat="news in results">
<p><a href="<?php echo url('news/show');?>/{{news.id}}">{{news.title}}</a></p>
<p>{{news.description}}</p>
</li>
</ul>
</div>
</body>
</html>

The app.js and newscontroller.js looks like the following.

app.js code:

var app = angular.module('NewsApp',[]);

newscontroller.js code:

app.controller("NewsController", function ($scope, $http) {
$scope.init = function () {
console.log('This is data');
$scope.results = [];
$http.get('http://localhost/laravel/public/news/').success(function (data) {
angular.forEach(data, function (value, index) {
$scope.results.push(value);
});
console.log(data);
console.log('This is data');
}).error(function (error) {
});
}
$scope.detail = function (id) {
console.log('This is data');
$scope.results = [];
$http.get('http://localhost/laravel/public/news/' + id + '/').success(function (data) {
$scope.results.push(data);
}).error(function (error) {
});
}
});

It worked, If you go to your http://localhost/project/public/shownews/ , It will show you the list of news with the link to the detail page.

If there is a better way out there to do this, please let me know. I think there must be as i am just a starter to AngularJS.

Add new methods to a resource controller in Laravel 4

Standard

So Its me again with Laravel 4 development. Today I am going to discuss about the Resource Controllers in Laravel 4 a bit.

For creating a Resource Controller in Laravel you can use the following command from within your project directory where artisan is located.

php artisan controller:make UsersController

After creating the Controller, Following methods will be created by default.

index, create, store, edit, update, destroy

What if a new method is needed. Scratching head!

The solution is simple.

Just add a route to that method separately, before you register the resource.

Route::get(‘users/status’, ‘UsersController@status’);
Route::resource(‘users’, ‘UsersController’);

I hope it will help someone.

Controller method not found, Error, Laravel 4

Standard

Today while Working with Resourceful Controller in Laravel 4, i was facing the following error.

Controller method not found

I googled and found the following link.

http://laravel.io/topic/30/routes-first-in-first-out

This did increase my knowledge but what i found is interesting, The problem was with my routes and Controller class.

Before when i was facing the error the route was.

Route::resource('groups', 'Admin\GroupController');

I renamed the GroupController to GroupsController and everything seems to be working fine. It seems that Groups and groups should match, Dont know why. But it worked.

Route::resource('groups', 'Admin\GroupsController');

Laravel 4: Organizing Controllers and views in folders

laravel
Standard

Its been so long that I have not written any blog post on my blog. So today i thought i should share something related to Laravel 4 framework.

I have been trying Laravel 4 for the last few days at office. Today i tried to organize the Controllers and Views in the folders so i faced some problems. But after some searching, I eventually figured it out. So if you ever want to use folders in Controllers and Views here is the Little guide.

Create a Folder Admin in app/controllers directory.

Add a SomeController.php file in it.

–app/
—- controllers/
——admin/SomeController.php

The code should look like this.
use BaseController;
use View;
class SomeController extends BaseController{
public function showAction(){
return View::make('admin.shownews'); //admin.shownews means shownews.php is in admin folder within views folder
}
}

routes.php should look like this:

Route::get('news/show','Admin\NewsController@showAction');

 

I hope this will solve the problem for any one who is searching for the solution.