sopheaks377@gmail.com (+855) 087443646 sok.sopheak152

Monday, March 13, 2017

how to get class name in controller folder on codeignither framework?

This solution to get the class name from controller folder using codeigniter framework.


/**
 * CodeIgniter

 * NOTE: If you change these, also change the error_reporting() code below
 */
    // define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'development');
/*
 *---------------------------------------------------------------
 * ERROR REPORTING
 *---------------------------------------------------------------
 *
 * Different environments will require different levels of error reporting.
 * By default development will show errors but testing and live will hide them.
 */
switch (ENVIRONMENT)
{
    case 'development':
        error_reporting(-1);
        ini_set('display_errors', 1);
    break;
    case 'testing':
    case 'production':
        ini_set('display_errors', 0);
        error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED);
    break;
    default:
        header('HTTP/1.1 503 Service Unavailable.', TRUE, 503);
        echo 'The application environment is not set correctly.';
        exit(1); // EXIT_ERROR
}
/*
 *---------------------------------------------------------------
 * SYSTEM DIRECTORY NAME
 *---------------------------------------------------------------
 *
 * This variable must contain the name of your "system" directory.
 * Set the path if it is not in the same directory as this file.
 */
    $system_path = 'system';
/*
 *---------------------------------------------------------------
 * APPLICATION DIRECTORY NAME
 *---------------------------------------------------------------
 *
 * If you want this front controller to use a different "application"
 * directory than the default one you can set its name here. The directory
 * can also be renamed or relocated anywhere on your server. If you do,
 * use an absolute (full) server path.
 * For more info please see the user guide:
 *
 * https://codeigniter.com/user_guide/general/managing_apps.html
 *
 * NO TRAILING SLASH!
 */
    $application_folder = 'application';
/*
 *---------------------------------------------------------------
 * VIEW DIRECTORY NAME
 *---------------------------------------------------------------

 * NO TRAILING SLASH!
 */
    $view_folder = '';

    // Set the current directory correctly for CLI requests
    if (defined('STDIN'))
    {
         chdir(dirname(__FILE__));
    }
    if (($_temp = realpath($system_path)) !== FALSE)
    {
        $system_path = $_temp.DIRECTORY_SEPARATOR;
    }
    else
    {
        // Ensure there's a trailing slash
        $system_path = strtr(
            rtrim($system_path, '/\\'),
            '/\\',
            DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR
        ).DIRECTORY_SEPARATOR;
    }
    // Is the system path correct?
    if ( ! is_dir($system_path))
    {
        header('HTTP/1.1 503 Service Unavailable.', TRUE, 503);
        echo 'Your system folder path does not appear to be set correctly. Please open the following file and correct this: '.pathinfo(__FILE__, PATHINFO_BASENAME);
        exit(3); // EXIT_CONFIG
    }
/*
 * -------------------------------------------------------------------
 *  Now that we know the path, set the main path constants
 * -------------------------------------------------------------------
 */
    // The name of THIS file
    // define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME));
    // Path to the system directory
    // define('BASEPATH', $system_path);
    // Path to the front controller (this file) directory
    // define('FCPATH', dirname(__FILE__).DIRECTORY_SEPARATOR);
    // Name of the "system" directory
    // define('SYSDIR', basename(BASEPATH));
    // The path to the "application" directory
    if (is_dir($application_folder))
    {
        if (($_temp = realpath($application_folder)) !== FALSE)
        {
            $application_folder = $_temp;
        }
        else
        {
            $application_folder = strtr(
                rtrim($application_folder, '/\\'),
                '/\\',
                DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR
            );
        }
    }
    elseif (is_dir(BASEPATH.$application_folder.DIRECTORY_SEPARATOR))
    {
        $application_folder = BASEPATH.strtr(
            trim($application_folder, '/\\'),
            '/\\',
            DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR
        );
    }
    else
    {
        header('HTTP/1.1 503 Service Unavailable.', TRUE, 503);
        echo 'Your application folder path does not appear to be set correctly. Please open the following file and correct this: '.SELF;
        exit(3); // EXIT_CONFIG
    }
    // define('APPPATH', $application_folder.DIRECTORY_SEPARATOR);
    // The path to the "views" directory
    if ( ! isset($view_folder[0]) && is_dir(APPPATH.'views'.DIRECTORY_SEPARATOR))
    {
         $view_folder = APPPATH.'controllers';

        // $router =& load_class('Router', 'core');
        // $controller_names = $router->fetch_class();
        // $method_name = $router->fetch_method();
        //echo $controller_names;
        $files1 = scandir($view_folder);
        $files2 = scandir($view_folder, 1);
        $scanned_directory = array_diff(scandir($view_folder,1), array('..', '.'));
        // echo "<pre>";print_r($scanned_directory);exit;
    }
    elseif (is_dir($view_folder))
    {
        if (($_temp = realpath($view_folder)) !== FALSE)
        {
            $view_folder = $_temp;
        }
        else
        {
            $view_folder = strtr(
                rtrim($view_folder, '/\\'),
                '/\\',
                DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR
            );
        }
    }
    elseif (is_dir(APPPATH.$view_folder.DIRECTORY_SEPARATOR))
    {
        $view_folder = APPPATH.strtr(
            trim($view_folder, '/\\'),
            '/\\',
            DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR
        );
    }
    else
    {
        header('HTTP/1.1 503 Service Unavailable.', TRUE, 503);
        echo 'Your view folder path does not appear to be set correctly. Please open the following file and correct this: '.SELF;
        exit(3); // EXIT_CONFIG
    }
    // define('VIEWPATH', $view_folder.DIRECTORY_SEPARATOR);
/*
 * --------------------------------------------------------------------
 * LOAD THE BOOTSTRAP FILE
 * --------------------------------------------------------------------
 *
 * And away we go...
 */
require_once BASEPATH.'core/CodeIgniter.php';




This is second solution to get directory , file controller and line.


function DirLineCounter( $dir , $result = array('lines_html' => false, 'files_count' => false, 'lines_count' => false ), $complete_table = true )
  {

      $file_read = array( 'php' );
      $dir_ignore = array();
    
      $scan_result = scandir( $dir );
    
      foreach ( $scan_result as $key => $value ) {
      
          if ( !in_array( $value, array( '.', '..' ) ) ) {
          
              if ( is_dir( $dir . DIRECTORY_SEPARATOR . $value ) ) {
              
                  if ( in_array( $value, $dir_ignore ) ) {
                    continue;
                  }
              
                  $result = DirLineCounter( $dir . DIRECTORY_SEPARATOR . $value, $result, false );
                
              }
              else {
              
              $type = explode( '.', $value );
              $type = array_reverse( $type );
              if( !in_array( $type[0], $file_read ) ) {
                continue;
              }
            
              $lines = 0;
              $handle = fopen( $dir . DIRECTORY_SEPARATOR . $value, 'r' );

              while ( !feof( $handle ) ) {

                  if ( is_bool( $handle ) ) {
                      break;
                  }

                  $line = fgets( $handle );
                  $lines++;
              }

              fclose( $handle );

              $result['lines_html'][] = '<tr><td>' . $dir . '</td><td>' . $value . '</td><td>' . $lines . '</td></tr>';
              $result['lines_count'] = $result['lines_count'] + $lines;
              $result['files_count'] = $result['files_count'] + 1;
                           
              }
          }
      }
    
      if ( $complete_table ) {
      
        $lines_html = implode('', $result['lines_html']) . '<tr><td></td><td style="border: 1px solid #222">Files Total: ' . $result['files_count'] . '</td><td style="border: 1px solid #222">Lines Total: ' . $result['lines_count'] . '</td></tr>';
        return '<table><tr><td style="width: 60%; background-color:#ddd;">Dir</td><td style="width: 30%; background-color:#ddd;">File</td><td style="width: 10%; background-color:#ddd;">Lines</td></tr>' . $lines_html . '</table>';
      
      }
      else {
        return $result;
      }
    
  }

  echo DirLineCounter( '.\application\controllers' );

Thursday, January 26, 2017

Requirement to run java web.

Requirement to run java web


1.       Install java runtime jre7 up to.
Image result for java jre
2.       Install apache  tomcat
Image result for tomcat
3.       Install PostgreSQL
Image result for PostgreSQL
1.    Download PostgreSQL installer for Windows
2.    Install PostgreSQL
3.    Verify the installation
Download PostgreSQL Installer for Windows
You need to download the installer from PostgreSQL Official website.
·         Go to the PostgreSQL official website, download section for Windows http://www.postgresql.org/download/windows/
·         Click on the download installer from EnterpriseDB
·         Choose the latest version to download. It takes few minutes to complete the download.
4.       Step to install postgreSQL
Install PostgreSQL step by step
Double click on the installer file, an installation wizard will appear and guide you through multiple steps where you can choose different options that you would like to have in PostgreSQL.
Install PostgreSQL Step 1
The following illustrates each step and its options for installation. If you install a different version, you may get additional steps.
Start Installing PostgreSQL

Install PostgreSQL Step 2
Specify installation folder, choose your own or keep the default folder suggested by PostgreSQL installer.
Enter the password for the database superuser and service account.
Install PostgreSQL Step 3
Enter the port for PostgreSQL. Make sure that no other applications are using this port. Leave it as default if you are unsure.
Install PostgreSQL Step 4
Choose the default locale used by the database.
Install PostgreSQL Step 5
You’ve completed providing information for the PostgreSQL installer. Click the Next button to install PostgreSQL
Install PostgreSQL Step 7
The installation may take few minutes to complete.
Install PostgreSQL Step 8
Click the Finish button to complete the PostgreSQL installation.
Verify the Installation
There are several ways to verify the installation. You can try to connect to the PostgreSQL database server from any client application e.g.,  psql, pgAdmin, etc.
The quick way to verify the installation is through the pgAdmin application.
First, click on pgAdmin III to launch it. The pgAdmin III GUI will display.

Second, double click on PostgreSQL 9.5 on the object browser. It will ask you for the admin password. Just enter the password you’ve used in the installation step.
Connect to PostgreSQL Server
Third, if everything is fine, the pgAdmin will display all the objects that belong to the server.


Congratulation! you’ve successfully installed PostgreSQL database server in your local system. Let’s learn various ways to connect to PostgreSQL database server.

Thursday, August 18, 2016

Tuesday, August 16, 2016

How to configure virtual host change local link?

Serve Multiple Domains By Using Virtual Hosts


Most people serve more than one domain on their Cloud Server. Whether for different domain names or different subdomains of the same domain, the procedure is the same.Our Linux Cloud Servers are built from a minimal installation image, meaning there are no additional applications installed beyond the base Operating System.To begin using your server, you initiate an SSH session to remotely connect to the Cloud Server. In order to make it more useful, you are responsible for installing applications. This can be done by compiling a program from the source code, or more commonly using the Package Manager to install an application from a repository.The most common application installed is a web server, such as Apache or Nginx.In order to serve a website you must set up the rest of the framework to serve your content, and then upload the actual content to your server. This entails installing any databases or Content Management Systems your site requires. For networking, you will need to add appropriate DNS records in the Rackspace Cloud control panel, to let the DNS system and the rest of the Internet know that your site is hosted from a Rackspace Cloud IP address.
Finally, you come to the part that allows your Cloud Server to deliver your websites, and for this you will need to create your sites as virtual hosts within your webserver configuration.

Procedure

Greatly simplified, the procedure for serving a website is as follows:
A browser sends a request to your Cloud Server’s IP address asking for the contents of ‘http://exampledomain.com/’ (your domain name).
Your web server jumps into action and says “Yes! I have something for you matching your request”. The web server does its ‘thing’ and serves up an http representation of your site, which is sent to the requesting browser. The browser then translates the http and parses it to a human-readable form.Simple, right? But how does your web server know what http to serve? If all you are serving is one website from the server, then it will serve the html in your /var/www/html directory, starting with index.html. We’ve all made a “Hello World” page before, right? But having a unique server for every website you want to serve is costly, and an inefficient use of your resources.

Virtual Hosts

This is a sample vhost configuration for Apache, serving domain1.com:

<VirtualHost \*:80>
  ServerName  domain1.com
  ServerAlias www.domain1.com
</VirtualHost>

server {
      server_name  www.domain1.com;
      rewrite ^/(.\*) http://domain1.com/$1 permanent;
}
Each configuration starts slightly differently, but the same principle applies - that particular virtual host will respond to queries for ‘domain1.com’ and ‘www.domain1.com’.

Multiple domains
So, serving different content for different domains is as simple as adding another virtual host.
Let’s say you have a subdomain called ‘blog.domain1.com’ serving a blog.
The basic creation process would be to create a folder in your public_html folder with the relevant files (let’s say a Wordpress install).
A virtual host would be created with the server_name or ServerName as ‘blog.domain1.com’ which would be configured to point to the blog files and folders in your public_html folder.Troubleshooting
This section shows you how to troubleshoot problems with Apache name-based virtual host configurations.
It will show you useful commands for testing your virtual host configuration, how to interpret their output, and how they help fix common virtual host configuration problems.Restart Apache
Before we make a start on learning to diagnose your issue, make sure that you have restarted Apache since the last changes you made to your Apache configuration files:
The output above was produced by the following virtual host file configuration:

NameVirtualHost \*:80   Turns on name-based host resolution and binds the virtual server to IP addresses and ports as in [1] above. The \* is a wildcard specifying all IP addresses.

<VirtualHost \*:80>   Configures the first and default virtual host in [2] & [3] above. It is the default because it is the first virtual host whose IP and port matches those in the NameVirtualHost directive before it.
 ServerName vh1.example.com
 DocumentRoot /var/www/vhosts/vh1
</VirtualHost>

<VirtualHost \*:80>   Configures the second virtual host in [4] above.
 ServerName vh2.example.com
 DocumentRoot /var/www/vhosts/vh2
</VirtualHost>
Now that that you’ve seen how a basic virtual host configuration looks and how it maps to Apache’s own configuration report, let’s use those reports to look at common configuration issues.

Tuesday, June 21, 2016

How to create project asp.net with angukarJS part1?

1- Open Visual Studio
2- Go go File -> new -> project -> web -> ASP.NET MVC 4  web application -> Add project name -> select basic -> view engine select Razor




3- Go to download Angular JS (https://code.anguarjs.org)
   -> dowload file Angular.js
   -> download file angular.min.js
   -> download file angular.route.js
   -> download file angular.route.min.js




4- Add library to project


5- Add bundle for render AngularJS library file in the view


code here :

using System.Web;
using System.Web.Optimization;

namespace ANGjs
{
    public class BundleConfig
    {
        // For more information on Bundling, visit http://go.microsoft.com/fwlink/?LinkId=254725
        public static void RegisterBundles(BundleCollection bundles)
        {
            bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                        "~/Scripts/jquery-{version}.js"));
            bundles.Add(new ScriptBundle("~/bundles/angular").Include(
                "~/Scripts/angular.js",
                "~/Scripts/angular-route.js"
                ));

            bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include(
                        "~/Scripts/jquery-ui-{version}.js"));

            bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                        "~/Scripts/jquery.unobtrusive*",
                        "~/Scripts/jquery.validate*"));

            // Use the development version of Modernizr to develop with and learn from. Then, when you're
            // ready for production, use the build tool at http://modernizr.com to pick only the tests you need.
            bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
                        "~/Scripts/modernizr-*"));

            bundles.Add(new StyleBundle("~/Content/css").Include("~/Content/site.css"));

            bundles.Add(new StyleBundle("~/Content/themes/base/css").Include(
                        "~/Content/themes/base/jquery.ui.core.css",
                        "~/Content/themes/base/jquery.ui.resizable.css",
                        "~/Content/themes/base/jquery.ui.selectable.css",
                        "~/Content/themes/base/jquery.ui.accordion.css",
                        "~/Content/themes/base/jquery.ui.autocomplete.css",
                        "~/Content/themes/base/jquery.ui.button.css",
                        "~/Content/themes/base/jquery.ui.dialog.css",
                        "~/Content/themes/base/jquery.ui.slider.css",
                        "~/Content/themes/base/jquery.ui.tabs.css",
                        "~/Content/themes/base/jquery.ui.datepicker.css",
                        "~/Content/themes/base/jquery.ui.progressbar.css",
                        "~/Content/themes/base/jquery.ui.theme.css"));
        }
    }
}
6- Modified _layOout.cshtml page for support AngularJS


7- Create one JS file (MyJs.js)


8- include js file (MyJS.js) to _layout.cshtml

code here :

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width" />
    <title>@ViewBag.Title</title>
    @Styles.Render("~/Content/css")
    @Scripts.Render("~/bundles/modernizr")
</head>
<body ng-app="MyJs" >
    @RenderBody()

    @Scripts.Render("~/bundles/jquery")

    @Scripts.Render("~/bundles/angular")
    <script src="~/Scripts/MyJs.js"></script>
    @RenderSection("scripts", required: false)
</body>
</html>

9- include code to JS file (MyJS.js)

code here: 

(function () {
    var app = angular.module('MyJs', ['ngRoute']);

    app.controller('HomeController', function ($scope) {

        $scope.Message = "This this project test demo asp.net mvc with angularJS. post on youtube and www.xzondev.com";
    });
})();

10- Add new controller (HomeController)

coder her :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace ANGjs.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/

        public ActionResult Index()
        {
            return View();
        }

    }
}

11- Add new action into controller for Get view


12- Call controller to show message
code here :

@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>

<div ng-controller="HomeController">
    <h1>{{Message}}</h1>
</div>


13- Run Test Application



This video show you to create project.This is link to videos: https://www.youtube.com/watch?v=GH0CinFVTaE


Video :

Monday, June 13, 2016

How to install window server 2012 R2?

hi all today i show you how to install window server 2008 R2



Foundation Topics
Windows Server 2012 R2 Hardware Requirements
As with previous Windows versions, your hardware must meet certain requirements for Windows Server 2012 R2 to function properly. First of all, Windows Server 2012 R2 requires a 64-bit processor; Microsoft has discontinued 32-bit software with this release of Windows Server. Table 2-2 outlines the minimum and recommended hardware requirements for Windows Server 2012 R2 as provided by Microsoft:

Table 2-2 Windows Server 2012 R2 Hardware Requirements
Component
Minimum Requirement
Microsoft Recommended
Processor
1.4 GHz
2 GHz or faster
Memory
512 MB RAM
2 GB RAM or greater
Available Disk Space
32 GB
40 GB or greater
Optical Drive
DVD-ROM drive
DVD-ROM drive
Display
Super VGA (800x600) monitor
XGA (1024x768) monitor
In addition, you must have the usual I/O peripherals, including a keyboard and mouse or compatible pointing device and a wired or wireless network interface card (NIC). If you can connect to a network location on which you have copied the contents of the Windows Server 2012 R2 DVD-ROM, you are not required to have a DVD-ROM drive on your computer. As with any other operating system installation, you will receive improved performance if you have a faster processor and additional memory on your system.
Further, when you install Windows Server 2012 R2 on an Itanium-based computer, you must have an Intel Itanium 2 processor and additional hard disk space. Computers with more than 16 GB RAM require additional disk space for paging, hibernation, and dump files. With disk space at an all-time minimum cost, it is easy to acquire a high-capacity hard disk. You will certainly need plenty of disk space on a server that will be a domain controller in a large domain.
Microsoft recommends that you also perform the following actions before installing Windows Server 2012 R2:
·         Disconnect uninterruptible power supply (UPS) devices: If you are using a UPS, disconnect its serial or USB cable before installing Windows Server 2012 R2. However, note that you do not need to disconnect other USB devices such as external hard drives, printers, and so on.
·         Back up data: Perform a complete backup of configuration information for your servers, especially network infrastructure servers such as DHCP servers. The backup should include the boot and system partitions as well as the system state data.
·         Disable antivirus software: Antivirus software can interfere with operating system installation.
·         Run the Windows Memory Diagnostic tool: This tool tests your computer’s RAM. For more information, refer to “Utility Spotlight: Windows Memory Diagnostic” at http://technet.microsoft.com/en-us/magazine/2008.09.utilityspotlight.aspx?pr=blog.
·         Provide mass storage drivers if needed: Save the driver file to appropriate media so that you can provide it during setup.
·         Note that Windows Firewall is on by default: Server applications that require inbound connections will fail until you create inbound firewall rules that allow these connections. For more information, refer to “Windows Firewall with Advanced Security Overview” at http://technet.microsoft.com/en-us/library/hh831365.aspx.
·         Prepare your Active Directory environment for Windows Server 2012 R2: Before adding a Windows Server 2012 R2 domain controller or updating an existing domain controller to Windows Server 2012 R2, prepare the domain and forest by running Adprep.exe. We discuss this tool in Chapter 13, “Installing Domain Controllers.”
Installing Windows Server 2012 R2
As already introduced in Chapter 1, “Introducing Windows Server 2012 R2,” you can install Windows Server 2012 R2 as either Server with a GUI, which presents a full graphical user interface, or Server Core, which presents only a command prompt window.
Installing a Windows Server Core Computer
As explained in Chapter 1, Windows Server Core includes a minimal version of the server software without the GUI; you perform all configuration tasks from the command prompt. Follow this procedure to install Windows Server Core and perform initial configuration tasks:
1. create name of server
2. select version ( windows 2008 (64bit))
3. click next
4. click next
5. clreate a vitual hard disk now
6. click next
7. click next
8. click create
9. select vitual name and than click start


10. click select from location browse to find window server file ISO
11. click start
12. select keyboard or input method ( united states- international

13. click next
14. click install
15. select window server 2012 R2 Standard Evaluation (server with a GUI)
16. click next
17. I accept the license term and than click next
18. click instal window only
19. click next
20. wait when it finish
21. it will restart
22. enter the password ( have strong password)
23. click
24. right click here(select insert Ctrl+Alt+Delete to signin)


This video show you to install window server:

Link : https://www.youtube.com/watch?v=RdF6kgPUEYU



Labels