Saturday, November 23, 2013

laravel pdo load data infile only imports first row."This command is not supported in the prepared statement protocol yet"

"This command is not supported in the prepared statement protocol yet". When I tried to use "load data infile" as a raw query on a table , It failed with this error , and after playing with many parameters in the query and tried many DB methods like DB::raw,DB::statement and DB::select, but nothing change the problem still exist . finally I can run the query but only the first raw was inserted,so The problem is in the query itself and Mysql server cannot under the end of line symbol , Just adding double back slash will solve this issue.
"LOAD DATA LOCAL INFILE 'filename'

                    INTO TABLE `tablename`

                    FIELDS TERMINATED BY ','

                    LINES TERMINATED BY '\\n'

                    (col1,col2,col3)";

Thursday, November 21, 2013

laravel 4 Cannot modify header information - headers already sent by (output started at

This error happened when you are using one of these statements in laravel 4 application :

 Redirect::to or  header('Location: ' . $url) 

Where your Laravel 4 application had sent a header to the screen before you decide to redirect the browser to other url . Sometimes this error caused by echo statement before the redirection , other output text or white space, But in my case the error because I have added a php closed tag:

?>  

in the end of the included files. So removing  this tag will bring the application back to normal behavior.

Tuesday, November 12, 2013

User is not returning back after been sent to oauth/authenticate on twitter api 1.1

When you trying to connect with twitter api 1.1 to authenticate a user , some time the twitter Authentication page will not come back to the callback function And you are very sure that the required parameters are valid and set .The first thing you should do is trying the code with another new client (Screen name), a client that was never subscribed to the application. if the new client can authenticate and return back to the application then the Problem is in the Permission levels of your application with twitter api, and to solve this issue then, every subscribed user should revoke the application and subscribe to it again.

Sunday, November 10, 2013

ie html contditional tage is not responding when using ie conditions

If you have a problem that ie tag is not working and the css file that you assign for this tag is not loading then the problem may be as I found it in the tag spaces. there must be no space in the tag before "If" and after ie9 .like what you see here :

<!--[if lt IE9]>
    <link rel="stylesheet" type="text/css" href="/assets/css/ie.css" />
<![endif]-->


 that mistake can happened if it like the following:

<!--  [if lt IE9]> or <!--[if lt IE 9]> or  <!--[if lt IE 9]  > 

also

<!  [endif]-->  or <![endif]  --> 
 
 
Note: Microsoft Stopped supporting IE condition tag in IE-10 and later Versions

Saturday, October 19, 2013

The Response content must be a string or object implementing __toString(), "boolean" given. Laravel4

"The Response content must be a string or object implementing __toString(), "boolean" given. Laravel4" .

This kind of error will kill you if yo are going to debug it Or trace it step by step, you will never find the solution because this error happens in response, I mean that it will be detected by the framework only after the response is ready to be rendered ,So it is as the message said "the response is boolean". Often it will happen in the view that some variables affect the response content . Just check the view variables one by one ,and remove each of them the try to run again . you will find the variable that cause this error. But before going in this path try to change the view by any other view page (blade-template) and see if the error is still there . if it is not , then the problem in the view page.

Sometime this error caused by directly returning false :

 
return false ;
Just change it to :
return 0;

Thursday, October 3, 2013

How to Exclude Folders From Git Gui on Windows

On the main Folder of your project create new file and name it .gitignore, This file will be read by git gui every time and all statemens will taken in account for Not tracking files or folders.

If you want to exclude a folder called "bin" , write a new line in this file "gitignore" like this:

bin/

here the bin folder located in the main folder will be excluded, if the folder you want to exclude is a subfolder,then you need to write :

bin/subfolder/

Ok, after that you have to order Git to remove cached file and remember what you have done here.
from the command line "cmd.exe" , write the following:

c:\project\git rm -r --cached .

//Don't forget the dot in the end of the command line.

then : run the following command:

c:\project\ git add .


Now any chenges made to the folder you specified in gitignore file will not be tracked.




Saturday, August 17, 2013

SQLSTATE[42S02]: Base table or view not found: 1146 Table - Laravel Eloquent

If you got this error and you know for sure  that you are having the table name in your  database, Then the problem is the prefix of the table, why is that ?
I have my model declared like this :

class tableName extends Eloquent{} 

Now eloquent will take in account that table name in the database is table_names , As you see, it will add underscore before the capital letter and "s" for plural .this will happen by default unless you explicitly declare the name of the table inside the model class like this:

class tableName extends Eloquent{

protected $table = 'tableName'; 


}

Or Avoid the Capital letter in the name of the model.

Saturday, August 10, 2013

[Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

This error happened if you are updating from MySQL 5.5 to MySQL 5.6 or when are using data folder that was on 5.5 server on 5.6 server . 
Anyway the solution is very easy and it is just a Warning but it is great to clear such things when you found it on your event log file.
 Add this line to MySQL configuration file , my.cnf or my.ini :

 explicit_defaults_for_timestamp = TRUE 

 restart your MySQL server and check your events log file.

Friday, August 9, 2013

NetworkError: 403 Forbidden Wamp Apache css js files

"NetworkError: 403 Forbidden   Wamp Apache css js files
SyntaxError: syntax error  <!DOCTYPE html>

Sometimes the Apache server cannot load static files other than html pages like images files, script and style files . when you have this error, that means some of the server configuration rules block the loading of these file and almost it will be in the Directory directive in http.conf file. So check the apache configuration file for Directory directive - Options Method - it may be duplicated in the main configuration file and the virtual host configuration file if you have virtual hosts, or it is not set .

if you get an error "forbidden" on directory with no index file then turn on the autoindex apache module or provide an index file if you don't want to list the files in that directory.
Other cause of this problem is that ,the server cannot reach the javascript files or there is a typing error in the syntax of the javascript tag check the script tag and the src attribute .

Tuesday, July 23, 2013

Adding new classes or library to laravel 4

The ugly, lazy and awful way: At the end of bootstrap/start.php , add an include('tools.php') and place your function in that new file.



The clean way: Create a library. That way it'll be autoloaded ONLY when you actually use it.
  • Create a library folder inside your app folder
  • Edit start/global.php to add app_path().'/library' to the ClassLoader::addDirectories( array.
  • Edit composer.json to add "app/library" to the autoload array.
  • Run composer dump-autoload
  • Create your library file, create a class in it, and add static functions to it
  • Call your class and static functions from your views.
Credit goes to this guy

Thursday, July 4, 2013

Less Compiler repeat (Duplicate) CSS rules (Definitions)

Sometimes After writing a new mixins (functions) for less and try to compiling the less files I find the produced css file include repeated definitions of the mixin children mixins , I mean that when writing a function like this :

In the LESS file I wrote the following:

.className{

h1{font-size:90%;}

p{font-size:80%;}

}



div.className;



In the output CSS file, It will be like this :

div.className h1{font-size:90%;}

div.className p{font-size:80%;}

div h1{font-size:90%;}

div p{font-size:80%;}


So, What is the Solution here ?
The problem showed a lack of knowledge in less mixins essentials . because when you create a mixin for a class, then in order to use it as a css class,  you should declare it  as a reference for the class of the element .So we will write or less file again as follows:
.className(){

h1{font-size:90%;}

p{font-size:80%;}

}



div.classname{

.className() ;

}


Now the output css file will be like the following:


div.className h1{font-size:90%;}

div.className p{font-size:80%;}






Saturday, June 29, 2013

Some Useful Css Rules, That I need it Always

1. When You Creat unordered list ul, by default there are some margins that you have to remove in order to align the list items li to their parent container ul: 

ul{
    margin:0 0 0 0;
    list-style-type: none;
    padding:0;
}

2. Targeting Microsoft Explorer 9 and before with CSS3 great rules use the valuable script PIE.

3. When you find your self want to apply rtl direction on list items <li> with  numbers like in pagination  links but you cannot , the direction will not change it is always ltr whether you put the page direction to rtl or ltr . to solve this assign a css display property   to the li element equal to flex.

 ul > li { display:flex;}
 
 
Note: Flex is a css3 property.

Css grid system : avoid box-sizing ie7 problems. boxsizing.htc



Responsive grid css frameworks are great solution to the problem of many screens visiting your site, there are many of these frameworks around, you can pick any one you like, depending on your needs, you may find small or large ones.


but the main problem with these frameworks is they are rely on javascripts, to solve issues like padding and borders on ie7, which can be solved using border-box in modern browsers.


If you are looking for css grid framework and you are concern about the size and the loading time of your page, then absolutely you will consider remove extra scripts to Speed up your page loading.


the best solution to this problem is to look at the grid system as layout lines and not content boxes. and put your content inside divs within the grid columns . So you can add padding and borders to the child div not to the grid column and that will not affect the grid layout.


Another thing to void is "Don't give the columns any extra margins that not required by the grid system".


If that is not working and you still have floating out columns then create a special grid columns rules that working only for ie7, that means you are going to change the percent numbers of each column.

Last option you have to accept javascript solution for this, Just Add :

*behavior: url(boxsizing.htc);

to the box-sizing css rule after you downloaded the file to your website. 


Another Solution is to download this script PIE.

Tuesday, June 25, 2013

Laravel-4 Tutorial-2 : Installation on Windows

The process of installation is clear and direct on windows and require 3 steps to do that : first , downloading the required packages, install them and check the path .

Downloading :
As I said in tutorial-1 , three main programs must be installed on your system Php,Composer And Git, Of course php will be installed with Apache server and mysql as a standard package (I use Wamp Server).

Download the Composer and Install it Just run the installation program , Then go to and download Git
Don't forget to choose the "Add to system Path" option when asked for .

Next check your installatio by running these commands from the command line :
C:\php --version
C:\composer --version
C:\git --version.
if it is ok and you will get a message of each program version.
Now you are ready to install Laravel-4 and begin creating your project.

Install  Laravel-4 using composer:
From the folder that you want to create laravel project in run the following command from command line:

composer create-project laravel/laravel 

The composer will connect to the git repository  and download the laravel
framework and all its components and their dependent packages.
even the Application key will be produces automatically by the installer. No need to do anything else just start configuring you application.

Monday, June 24, 2013

Laravel-4 Tutorial-1 : Things to know before Start developing on Windows

You Need To Install Composer And Git in order to work with  Laravel-4 and Packages Installation.
Three Folders must be added to your path    composer, php and  git.


Composer and Laravel

People on Laravel Project Didn't want to produce a strange php framework that don't know anything about the other Packages on the internet and that will enforce the developer to create his own version of every thing he needs to develop an application. instead the developer can benefit from other developers and can inject their standard packages into his project without the need to start from zero point again.
So,Composer  is just a utility that will help developers to install other packages into their project . That's it.

From Composer Site Documentation :

Composer is not a package manager. Yes, it deals with "packages" or libraries, but it manages them on a per-project basis, installing them in a directory (e.g. vendor) inside your project. By default it will never install anything globally. Thus, it is a dependency manager.

Also,  We need Composer to install the framework that we need like Laravel, Why we need composer .

You will get this error:

failed to open stream: Unable to find the socket transport
 "ssl" - did you forget to enable it when you configured PHP?

When try to install any package using composer and you didn't enable openssl extension

You will get this error :

'git' is not recognized as an internal or external command,  operable program or batch file.

When you try to run composer to install a packages that reside on git repository,That means the git program is not installed or is not added to your PATH.


Why do we need Git :

From Composer Site Documentation :
"To install packages from sources instead of simple zip archives, you will need git, svn or hg depending on how the package is version-controlled. "

-> For Tutorial-2

Sunday, June 16, 2013

Whoops! There was an error in Laravel-4 Startup

Suddenly When I tried to reach laravel 4 Documentation on my server ,a strange colorful screen came out  saying  :

"Whoops! There was an error"







This is a debug stack trace detailed page taking from Symfony Package which is used with laravel packages as  an error stack trace  display script .
(Sorry.. Laravel-4 going to be elites software not for anyone , and I think it will lose its popularity )

Ok. How to solve this issue , As I said this is a detailed information about the error you got,If you are lost in these crowded tech information then you can reach the single line error page by changing the variable debug value from True to False in the configuration file app.php.
You can find this file in app/config/ folder .
After changing the value  to false regenerate the error again and you will get a single line error telling you what is the problem.


Tuesday, June 4, 2013

Convert Twitter Bootstrap css file from LTR to RTL using Node.js R2 Module on Windows 7

I am using this library (twitter bootstrap) a lot on many RTL (Right To Left) sites , But it is not supporting RTL css rules, for that a lot of developers created RTL version of twitter bootstrap css library and that is great if they keep there products up to date .but unfortunately they don't. So we have to find a proper way to help our self solving this issue. How to do that :

First : Download and install Node.js on Windows 7.

Go to Node.js Site Download page and Download Node.js Installer . be sure to check the npm option to be installed on your computer from the installation wizard :



What is Npm ?
Npm is Node Packaged Modules where you can find a lot of modules that work with node.js to ease a lot of functions that you don not need to create by your self like Mysql Package which is A node.js driver for mysql.

Second: Download  and install Node.js Module (R2):

From the Command line Just enter this  command :

npm install -g R2

-g : this attribute will add R2 to the system path so you can Run it from any place.

 Third: Run R2 on the LTR css file to convert it to RTL css file.

go to the folder that contain your css file that you want to convert it and from the command line type the following :

r2 [the name of the original ltr file] [the name of the rtl file]
In the twitter bootstrap case we neet to do the following:
r2 bootstrap.css bootstrap.rtl.css

And hopppppaaa     .................

Tuesday, May 28, 2013

Wamp Server is Not loading Postgres server Extensions php_pgsql.dll and php_pdo_pgsql.dll

It is not enough to uncomment the  relative lines in the php configuration file on Windows but Also you have to add this line to the Apache Server configuration file :

LoadFile "C:/wamp/bin/pgsql/pgsql9.2.41/bin/libpq.dll"

Change the Path to suite your configuration .

Thursday, May 23, 2013

Error displaying the error page: Application Instantiation Error (Windows 7 + Wamp server)

When startup joomla on a new php version 5.4.15 "Error displaying the error page: Application Instantiation Error" The Problem is the mysql extension is not running or not loaded by Php, you can check that by display the loaded extensions by usin this command :
$loaded_extensions = get_loaded_extensions();
echo '<pre>';
print_r($loaded_extensions);
echo '</pre>';
exit;
you will see n the resulted list only the default extensions That means the Apache server dont know where to fnd those extensions, I mean the extension_dir is not clearly configured in apache configuration file . to solve this issue go to php version folder, and find the file phpForApache.ini (on Wamp server) then write the right address to the extensions directory. like this :
extension_dir = "c:/wamp/bin/php/php5.4.15/ext/"
check again that this line is uncommented (the ; is removed). restart your server again and it will load the extensions from the right place. 

Note: When You change anything in phpForApache.ini for the php version  it must be not loaded, that means the php version thats hold this file must be not running.

Note: If you are not on Wamp Server you have to check you phpinfo() page to see where is your php.ini reside.

Friday, May 3, 2013

Wamp cannot load extensions- php5apache2_4.dll - Windows 7

Wamp is Automating every thing that's the great thing of this web server , So , If you enable the extension from the menu (Icon Tray-> Php Menu  ->Extensions) ,Wamp will un-comment the extension in your php.ini  automatically , you don't need to do anything.

Please Note : that there are three Php Initial files came with Wamp , one in Php Directory , the second in Apache->Bin Directory and the third is called phpForApache.ini and located in php directory.

We are talking here about the second file that located in Apache->Bin  folder and that file must be showed in the results of Phpinfo() function as "Loaded Configuration File " variable .

So, Don't Comment anything . wamp will do it for you , what you need to do Solve Any Problem is to check the Variable 'Extension_dir' in php.ini file , the directory must be related to the apache folder .I meant that the path to the Php extensions directory must be not  = "ext", Because that mean, the folder is inside the Apache->Bin  Folder , and that's not right . Just write the full Path to the extension Directory.

Another thing to mention here that is very important if you are going to play with wamp , when you switch the php version through the system tray menu, Wamp  will copy the phpForApahce.ini from php version directory to Apache version directory .
Then it will change  any line contain "LoadModule  And Php" with the  line from another file called "wampserver.conf" that is located in php folder which is relevant to the apache version.

Two files are  important to wamp to load php extension successfully on is the php.ini in the php directory and the other is in apache/bin directory they must include the same extension and the same extension_dir






php5apache2_4.dll into server: The specified module could not be found.

From event viewer in Windows I got this error, After trying to Add Apache 2.4 to Wamp 2.2 , Where I cannot run php scripts with php5.4.14 .
The Problem Was I downloaded the non thread safe version of php , So to solve this issue just download the thread safe PHP.
It is Supposed that you already added these lines to the Apache configuration file  :

 DirectoryIndex index.php index.php3 index.html index.htm
 DirectoryIndex index.php index.php3 index.html index.htm
   AddType application/x-httpd-php .php
  AddType application/x-httpd-php .php   

  AddType application/x-httpd-php .php3   
  AddType application/x-httpd-php .php3

Thanks 

Friday, April 19, 2013

Apache 2.* VirtualHost Suddenly Stop working for no Reasons

It cost me two hours looking for the solution , and at last I found it :

The Apache virtual hosts were working great then suddenly I cannot reach those virtual hosts , only the local host is working, It seems to be difficult to find the problem when you are very sure that your files are OK and you didn't touch any of them or change their contents. then who did that ? who did change the configuration files content. 
To virtual hosts for Apache on windows you need three files : httpd.conf, httpd-vhosts.conf  those located in the server folder and host file which is part of the windows system and located at the folder
/windows/system32/drivers/etc/host.
Some Applications can reach your host and change its content, even changing its security status like Microsoft updates.

This is what happened , the host file security  was changed to be secured , So Apache cannot reach again unless you remove the security flag or Run Apache As Administrator.



Friday, March 22, 2013

Create a Custom Validation Rules in Laravel 3


1.Open Start.php in the application folder and add a path map to your class that you are going to use in validation

Autoloader::map(array(

 'customValidator' => __DIR__.DS.'libraries'.DS.'Cvalidator.php',

));






in this code,   the name of my custom validator class is: 'Cvalidator.php'
and reside in  the directory : application/libraries/
Now, The system will know the place of your class .
2. Also in the smae file 'start.php' register your new validation rule as follows:


Laravel\Validator::register('customrule', function($attribute, $value, $parameters)

{

 return customValidator::CheckThis($attribute, $value, $parameters);

});




3.Next you need to create your class with methodes that will handle the validation staff. but assure that you put in the right path that you map it in start.php, here an example: 

Don't Extend the Laravel Validation Class



<?php class Cvalidator{ public static

 CheckThis(){ 

 //do the validation heare then: return true or false only return true;
}

Saturday, March 16, 2013

php artisan key setup on laravel

First When I tried to generate an application key for Laravel application I got this error :

'php' is not recognized as an internal or external command,
operable program or batch file.  


That means the system does not know what this command is , you have to tell your system what is 'php' and that can be done by adding php folder to the system path :
1-  On start command line type environment and choose from results the system environment not the account environment.




2.Click on Environments Variables 
3.click on Edit then add the path to php.exe on the end of the line , dont add the file name php.exe to the path, just the folder that contain the file.
4. reboot the system.








Now for Laravel to run artisan :

1. Go to the application folder in your Laravel project and open the file application.php, and find the key value :
'key' => ''.
this value must be empty nothing inside it .
2.opend the command screen by typing cmd.exe on the start run line.
3. on the command prompt change directory to Laravel Directory.
4. Type  php artisan key:generate.
the system will response by this message " Configuration  updated with secure key"
the Key value in application.php file will be changed by the system.
Thats All ,

For Laravel-4 the same process can be  applied

 

Sunday, February 10, 2013

Wamp on Windows 7 Startup

Problem:
Localhost is running automatically on Windows 7 start up .
To Solve that Just change its Startup type from Automatic to Manual  through the services panel .
From the command prompt enter : Services.mcs
Enter
look for Wampapache and Wampmysqld  Services and change their startup type to Manual



If you want to run Wamp whenever Windows startup then change manual to Automatic

Wednesday, January 30, 2013

How to get the view and layout in Joomla 2.5

In Joomla 2.5 if you want to know the requested uri :
 $uri =& JURI::getInstance(); echo 'Request URI is ' . $uri->toString() . "\n"; 
And for the view and layout you can do the following :
echo (JRequest::getCmd('view')) ."Is the View"; 

echo( JRequest::getCmd('layout'))."Is the Layout"; exit;  
Why is that ? Because Joomla 2.5 using SEF routing that changes the requested route to a new segments related to your category's id and name as well as to the article's id and alias . Which will leads you to no where if you programming a joomla module and need to extract the coming request to check the required view and layout.

Monday, January 28, 2013

Apache 2.* Wamp Stop Working on Orange Icon

On Windows 7, Wamp server  used to run smoothly with no problems and suddenly the server stop working, if the server is ok the tray icon will be in green color, that  is sign of healthy wamp server, but now  I get only at orange color tray icon.
As usual the first thing to do in thiss case is to check the logs file to see the error message that was saved there, but another shock was there is no error message in Apache log files.

The Problem was that ,Skype is conflicting Apache because Skype use port 80 as an alternative connection port, So when Skype is started before you start apache it will use the 80 port, but if Skype is started after then port 80 will be dominated by Apache on Wamp.

What to do :
In Skype from the Main menu choose Tools then Options then Advanced and uncheck the chckbox that is titled by  "use port 80 and 443 as alternatives for incoming connections"

Happy Wamping.

Tuesday, January 22, 2013

Apache 2.* only serve the first virtual host - Windows 7 + WAMP

This is a problem that cost me 3 days googling and searching every where without any hints or clues to the way that I should take to solve this problem.
But It was very easy if you try to stop thinking that google can solve all of yourproblems , just relax and try to solve it by yourself.
That's what I did , the server was running great for more than 6 months now, and suddenly I cannot reach my virtual hosts.
My  $1 million dollar advice to any one face such a problem or any other one is "First Check Log files".
What I had there is 


[error] (OS 11001)No such host is known.  : Could not resolve host name

And that means the system don't know how to reach the name domain that you write in the address bar. So the Problem was in Domain Resolution. that lead to host file.

When I checked the host file I cannot find any problem. All virtual hosts had their right IP addresses "127.0.0.1".
But Apache Said he cannot reach this file , means  there are security rules prevent apache from opening this file. 
Yes, It is a secured file by windows and to allow any application to use this file you have to give the application the right permissions. So Apache on windows to be able to read host file and run virtual host must be "Run As Administrator". That is it .

Long Road for Dummies like me , but a very good tutorial to know that I can solve things my self.